向以下的方法提交数据:1,c4ca4238a0b923820dcc509a6f75849b,1(传参时全部为String)
public static void UserRegister(String UserName, String PassWord_md5, String QQNumber) {
//注册用户,写入数据库,如果有QQ。
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:ZLD_DB.db");
c.setAutoCommit(false);
stmt = c.createStatement();
String sql = "INSERT INTO Users (UserName,Password,QQ) "
+ "VALUES ("+UserName+","+PassWord_md5+","+QQNumber+");" ;
stmt.executeUpdate(sql);
stmt.close();
c.commit();
c.close();
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("注册操作完成");
}
会抛出错误:org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: c4ca4238a0b923820dcc509a6f75849b)
然后就自己退出了……
请问这样写有什么问题?造成卡退的原因又是什么呢?
改为:
String sql = "INSERT INTO Users (UserName,Password,QQ) "
+ "VALUES (\'"+UserName.toString()+"\',\'"+PassWord_md5.toString()+"\',\'"+QQNumber.toString()+"\');" ;