我如何将逗号字符串插入sqlite db(how do i insert comma string to sqlite db)
我正在尝试使用此代码:
String message = "this is david's house"; String sql = "INSERT into " + TABLE + "(message) VALUES ('" + message + "')"; db.execSQL(sql); db.close();为了将字符串插入db,但得到此异常:
01-27 14:52:01.083: E/Database(727): Failure 1 (near "id": syntax error) on 0x12a038 when preparing 'INSERT into calls_table (message) VALUES ('this is david's house')'.如何让SQLite获得逗号?
i'm trying to use this code:
String message = "this is david's house"; String sql = "INSERT into " + TABLE + "(message) VALUES ('" + message + "')"; db.execSQL(sql); db.close();in order to insert the string into the db, but get this exception:
01-27 14:52:01.083: E/Database(727): Failure 1 (near "id": syntax error) on 0x12a038 when preparing 'INSERT into calls_table (message) VALUES ('this is david's house')'.How can i make the SQLite get the comma?
最满意答案
你必须逃脱'正确:
String message = "this is david''s house";或者,如果sqlite支持它(我不知道),参数化查询更好。
并且只是提到它: '不是逗号,它是撇号 (至少我认为这是正确的名称,我经常混淆那个名称)。
You have to escape the ' properly:
String message = "this is david''s house";Or, if sqlite supports it (I don't know), parameterized queries are better.
And just to have mentioned it: the ' is not a comma, it's an apostrophe (at least I think that's the correct name, I often confuse the name for that one).
更多推荐
发布评论