我在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
电子邮箱:[email protected]
网址:www.ahlam.com
电话1:123456789
电话: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);

07-28 03:34