Android SQLite 插入 TABLE 值
Android SQLite INSERT INTO TABLE VALUES
我收到这个错误:
android.database.sqlite.SQLiteException: near ":12": syntax error (code 1): while compiling: INSERT INTO TIME VALUES(15:12);
我的代码如下:
SQLiteDatabase db = openOrCreateDatabase("timedb", Context.MODE_WORLD_WRITEABLE, null);
s = (timePicker.getCurrentHour().toString() +" : " + timePicker.getCurrentMinute().toString());
s = "'" + s + "'";
db.execSQL("CREATE TABLE if not exists TIME"+" ("+ "times" +" VARCHAR(100)"+");");
query = "INSERT INTO TIME"+ "VALUES"+"("+s+")";
db.execSQL(query);
startActivity(new Intent(Preferences.this, MainActivity.class));
我敢肯定,我从这段代码中得到了错误。有人可以帮助我吗?
您在将值传递给查询时遗漏了单引号
试试看可能对你有帮助
query = "INSERT INTO TIME"+ " VALUES "+"('"+s+"')";
我收到这个错误:
android.database.sqlite.SQLiteException: near ":12": syntax error (code 1): while compiling: INSERT INTO TIME VALUES(15:12);
我的代码如下:
SQLiteDatabase db = openOrCreateDatabase("timedb", Context.MODE_WORLD_WRITEABLE, null);
s = (timePicker.getCurrentHour().toString() +" : " + timePicker.getCurrentMinute().toString());
s = "'" + s + "'";
db.execSQL("CREATE TABLE if not exists TIME"+" ("+ "times" +" VARCHAR(100)"+");");
query = "INSERT INTO TIME"+ "VALUES"+"("+s+")";
db.execSQL(query);
startActivity(new Intent(Preferences.this, MainActivity.class));
我敢肯定,我从这段代码中得到了错误。有人可以帮助我吗?
您在将值传递给查询时遗漏了单引号
试试看可能对你有帮助
query = "INSERT INTO TIME"+ " VALUES "+"('"+s+"')";