我要将其插入表中的歌曲名包含一个“”(撇号),因此,执行请求时出错。我怎么能修好它

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

我得到sname运行时所以..sNe= /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的单词,这会给我带来错误。

最佳答案

理论上,您可以在sql中将'转义为''
不过,最好使用变量绑定。将SQL中的字符串文本替换为?,并在数组中提供相应的Strings个数:

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

10-08 12:21