我如何将逗号字符串插入sqlite db(how do i insert comma string to sqlite db)

编程入门 行业动态 更新时间:2024-10-28 20:31:50
我如何将逗号字符串插入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).

更多推荐

本文发布于:2023-07-26 18:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279307.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:逗号   字符串   如何将   sqlite   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!