我试图使用方法如下执行INSERT
sqlite的语句到我的数据库:包括SQLite中插入语句斜线
public void insertBluetoothPath(String path, String build) {
String[] ColumnName = new String[1];
ColumnName[0] = "path";
SQLiteDatabase myDB = null;
myDB = this.openOrCreateDatabase(DB_PATH, MODE_PRIVATE, null);
myDB.execSQL("INSERT INTO phones VALUES(" + build + ", " + path + ");");
myDB.close();
}
和我打电话使用 insertBluetoothPath(finalPath, phoneBuild);
与变量的方法 String phoneBuild = Build.MODEL;
和String finalPath = "/mnt/sdcard"
但是,我收到语法错误异常
sqlite returned: error code = 1, msg = near "/": syntax error
Failure 1 (near "/": syntax error) on 0x2b3ca8 when preparing 'INSERT INTO phones VALUES(sdk, /mnt/sdcard);'.
如何在数据库中插入斜杠?提前致谢。
尝试使用准备好的语句 - http://stackoverflow.com/questions/433392/how-do-i-use-prepared-statements-in-sqlite-in-android – Eugene
你应该使用转义字符。检查这个帖子。 http://stackoverflow.com/questions/4132996/escape-special-characters-in-sqlite –