In my database Inbox table have column name path to keep path of files but when i am trying to delete that record on the base of path the FATAL exception is thrown by Emulator.
// Deleting single File
public void deleteFile(File file) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_INBOX, KEY_PATH + " = "+file.getPath(),null);
db.close();
}
Exception is :
FATAL EXCEPTION:main
android.database.sqlite.SQLiteExceprion: unrecognized token:"1kbFile"(code 1):,while compiling :DELETE inbox WHERE path=1kbFile.txt.
1kbFile.txt is path that i want to delete which is already saved in db. how can i solve this?
Try to add '
to your file name, like this :
db.delete(TABLE_INBOX, KEY_PATH + " = '" + file.getPath() + "'", null);
Or you could also try to use separate parameters :
String whereString = KEY_PATH + " = ?";
String[] whereArgs = new String[] {file.getPath()};
db.delete(TABLE_INBOX, whereString, whereArgs);
Use ' around the values. Eg:
db.delete(TABLE_INBOX, KEY_PATH + " = '"+file.getPath()+"'",null);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.