无法在SQLite数据库中更新表:android

时间:2013-05-01 04:12:36

标签: android android-sqlite

我在SQLite数据库表中更新了其他项目它工作正常,在这种情况下,一切似乎都很好,但显示错误。这是更新表的代码:

public void updateNamePhone(ArrayList<String> seekerList, ArrayList<String> nameList, ArrayList<String> phoneList) {
    // TODO Auto-generated method stub

    try{
    for(int i=0;i<seekerList.size();i++){
    ContentValues editCon = new ContentValues();
    editCon.put(KEY_NAME, nameList.get(i));
    editCon.put(KEY_PHONE, phoneList.get(i));               
    ourDatabase.update(DATABASE_TABLE, editCon, KEY_REGID+"="+seekerList.get(i), null);     
    }

    }catch(Exception e){
        System.out.println(e.getMessage());
    }

}

三个数组列表是:

seekerList:[Chandigarh, Mohali, Panchkula, Ambala]
nameList:[Vikram, Ashish, Rohit, Sunny]
phonelist:[989,98763,564838,33224]

创建时所有表格列都是文本类型。

发现错误:

05-01 09:08:11.234: E/Database(25886): updateWithOnConflict |Error updating table = seekersList
05-01 09:08:11.234: I/System.out(25886): no such column: Chandigarh: , while compiling: UPDATE seekersList SET person_phone=?, person_name=? WHERE person_regid=Chandigarh

2 个答案:

答案 0 :(得分:0)

将您的更新更改为

ourDatabase.update(DATABASE_TABLE, editCon, KEY_REGID+"=?",   
                             new String[]{seekerList.get(i)}); 

答案 1 :(得分:0)

这是您的错误原因:

  

没有这样的专栏:Chandigarh :,编译时:UPDATE seekersList SET   person_phone =?,person_name =?在哪里person_regid = Chandigarh

你需要在任何搜索过的字符串周围加上引号:

  

UPDATE seekersList SET person_phone =?,person_name =? WHERE person_regid ='Chandigarh'

所以在您的代码编辑中如下:

ourDatabase.update(DATABASE_TABLE, editCon, KEY_REGID+"='"+seekerList.get(i)+"'", null);