android.database.sqlite.SQLiteException:near“ce”:语法错误(代码1):,同时编译:INSERT INTO

时间:2016-03-03 10:50:52

标签: android sqlite

我正在按如下方式初始化变量:

String separator = "" ;
String insertQuery1 = "INSERT INTO " + PhoneContactsTable.TABLE_PHONE_CONTACTS + " (" +
          PhoneContactsTable.KEY_NAME +"," +  PhoneContactsTable.KEY_PH_NO +"," 
          + PhoneContactsTable.KEY_SNID +","+ PhoneContactsTable.KEY_EMAIL +") VALUES " ;

StringBuilder insertQuery2 = new StringBuilder();

我正在生成insertQuery2(stringbuilder),如下所示:

try
{
    JSONArray jsonArray = new JSONArray(returndResultForSNID);

    for(int i = 0; i < jsonArray.length(); i++)
    {
        snid = jsonArray.getJSONObject(i).getString("snid");
        insertQuery2.append(separator).append("('").append(contactNameArr.get(i).toString()).append("','").append(contactPhoneNumberArr.get(i).toString()).append("','")
        .append(snid).append("',").append("''").append(")");
        separator = "," ;
    }

}
catch (Exception e)
{
    System.out.println( "Could not parse malformed JSONArray: " + e.toString() );
}

我正在创建最后一个String作为插入数据库的insertQuery3:

try
{
    String insertQuery3 = insertQuery1 + (insertQuery2.toString()).toString();
    phoneContactsDAO.open(false);
    phoneContactsDAO.addFullStringToDb(insertQuery3);
    phoneContactsDAO.close();
}
catch (Exception e)
{
    System.out.println( "Could not added into database: " + e.toString() );
}

我的数据库查询如下所示:

public void addFullStringToDb(String insertQuery3) 
{
  database.execSQL(insertQuery3);   
}

此代码适用于4部电话。但是没有在第五台设备上工作

0 个答案:

没有答案