我試圖使用方法如下執行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 –