gpt4 book ai didi

android - SQLite (1) 靠近 "M": syntaxs error

转载 作者:搜寻专家 更新时间:2023-10-30 23:15:49 25 4
gpt4 key购买 nike

我在 android 中创建了这个表:

     String CREATE_TABLE="CREATE TABLE " + db_NAME + " ("
+ row_ID + " INT PRIMARY KEY AUTOINCREMENT,"
+ row_NAME + " TEXT, "
+ row_EMAIL + " TEXT, "
+ row_WEBSITE + " TEXT, "
+ row_TELEPHONE1 + " TEXT, "
+ row_TELEPHONE2 + " TEXT, "
+ row_TELEPHONE3 + " TEXT, "
+ row_TELEPHONE4 + " TEXT, "
+ row_TELEPHONE5 + " TEXT;";
db_name.execSQL(CREATE_TABLE);

我正在尝试插入以下数据:

姓名:Ahlam M. Hussain

邮箱:ahlam@ahlam.ahlam

网址:www.ahlam.com

电话#1:123456789

电话#2:0987654321

电话#3:

电话#4:

电话#5:

使用以下字符串:

     String sql_entry = String.format("Insert into %s (%s, %s, %s, %s, %s, %s, %s, %s) values (%s, %s, %s, %s, %s, %s, %s, %s);",tab_NAME, row_NAME, row_EMAIL, row_WEBSITE, row_TELEPHONE1, row_TELEPHONE2, row_TELEPHONE3, row_TELEPHONE4, row_TELEPHONE5, name, email, website, telephone1, telephone2, telephone3,telephone4, telephone5);
ourDatabase.execSQL(sql_entry);

其中:( row_NAME, row_EMAIL, row_WEBSITE, row_TELEPHONE1, row_TELEPHONE2, row_TELEPHONE3, row_TELEPHONE4, row_TELEPHONE5) 是列名”

和 : (name, email, website, telephone1, telephone2, telephone3,telephone4, telephone5) 是要插入数据库的数据

当我运行应用程序时,我收到一条错误消息:

      SQLiteLog        (1) near "M" : syntax error

那么问题是什么???

最佳答案

用单引号将非数字值括起来。

String sql_entry = String.format("Insert into %s (%s, %s, %s, %s, %s, %s, %s, %s)"
+" values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
tab_NAME, row_NAME, row_EMAIL, row_WEBSITE, row_TELEPHONE1, row_TELEPHONE2,
row_TELEPHONE3, row_TELEPHONE4, row_TELEPHONE5, name, email, website,
telephone1, telephone2, telephone3,telephone4, telephone5);

关于android - SQLite (1) 靠近 "M": syntaxs error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13991224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com