sqlite.SQLiteException:near"s":语法错误:因为撇号

Sha*_*yaz 2 sqlite android cursor sqliteopenhelper

我要将其插入到我的表中的歌曲名称包含"'"(撇号),因此,在请求被执行时会出错.我该如何解决呢?

Cursor pid = mDB.rawQuery("select Id  FROM MusicPlayer WHERE "Path ='" + sname + "';", null);
Run Code Online (Sandbox Code Playgroud)

我得到sname运行时所以.. sname =/mnt/sdcard/Now Thats What I Call Music 85 [Bubanee]/16 - Let's Get Ready To Rhumble (100% Radio Mix) - PJ & Duncan.mp3

我得到以下错误..

android.database.sqlite.SQLiteException: near "s": syntax error: , while compiling: SELECT Id FROM MusicPlayer WHERE Path ='/mnt/sdcard/Now Thats What I Call Music 85 [Bubanee]/16 - Let's Get Ready To Rhumble (100% Radio Mix) - PJ & Duncan.mp3';

因为sname包含let's带有'错误的单词.

laa*_*lto 10

从理论上讲,你可以'''在SQL中那样逃避.

但是,最好使用变量绑定.用SQL替换SQL中的字符串文字,?String在数组中提供相应的s 数:

Cursor pid = mDB.rawQuery("select Id  FROM MusicPlayer WHERE Path = ?;",
    new String[] { sname });
Run Code Online (Sandbox Code Playgroud)