我是被动的英语.. 我有一个数据库连接
String sql = "INSERT INTO " + TABLE_TRANSAKSI
+ " (kdCabang, kdRoti, noNota ) " + " VALUES ( '"
+ kdCabang + "' , '" + cursor.getString(0) + "' , '"
+ noNota + "'";
dbHelper.getWritableDatabase().execSQL(sql);
Log.d("INSERT noNota", sql);
我认为我的代码已经是真的..但是在我的日志中......
09-08 15:23:53.811: ERROR/Database(21975): Failure 1 (near "'1'": syntax error) on 0x343fc0 when preparing 'INSERT INTO TRANSAKSI (kdCabang, kdRoti, noNota ) VALUES ( 'TKRS' , 'KRKJ' , '1''.
谁能说出我的错?
谢谢be4
答案 0 :(得分:6)
你错过了一个右括号。
应该是:
String sql = "INSERT INTO " + TABLE_TRANSAKSI
+ " (kdCabang, kdRoti, noNota ) " + " VALUES ( '"
+ kdCabang + "' , '" + cursor.getString(0) + "' , '"
+ noNota + "')";
生产:
'INSERT INTO TRANSAKSI (kdCabang, kdRoti, noNota ) VALUES ( 'TKRS' , 'KRKJ' , '1')'.
所有这些都在错误信息中 - 你需要学会阅读和理解它们。
答案 1 :(得分:3)
您最后没有关闭支架 请检查第4行
String sql = "INSERT INTO " + TABLE_TRANSAKSI
+ " (kdCabang, kdRoti, noNota ) " + " VALUES ( '"
+ kdCabang + "' , '" + cursor.getString(0) + "' , '"
+ noNota + "')";
答案 2 :(得分:1)
关闭值的括号,如下所示
String sql = "INSERT INTO " + TABLE_TRANSAKSI
+ " (kdCabang, kdRoti, noNota ) " + " VALUES ( '"
+ kdCabang + "' , '" + cursor.getString(0) + "' , '"
+ noNota + "')";