SQLite更新问题

时间:2011-10-28 15:51:27

标签: android sqlite

我在sqlite [android]

中遇到更新查询的问题

这是一个更新方法:

public int Updater(String pass, String na, String sur, String cou,String log){
    ContentValues cv=new ContentValues();

    cv.put(colPassword, pass);
    cv.put(colName, na);
    cv.put(colSurn, sur);
    cv.put(colCountry, cou);
    return sqLiteDatabase.update(Usr_TABLE, cv, colLogin+"="+log, new String []{colLogin});   
}

我收到错误:

Error updating Name=qwewqeq Login=tesg Surname=gfgfg Country=ewrwe Password=dfsdfds using UPDATE USERS SET Name=?, Login=?, Surname=?, Country=?, Password=? WHERE Login=bla

以后

完成尚未停用或关闭的游标

BUT

我关闭了所有内容

这里是调用更新:

public void FinishCl(View v){
    sql = new SQLiteAdapter(this);
    editps = (EditText) findViewById(R.id.Pasek);
    edytn = (EditText) findViewById(R.id.wyname);
    editsn = (EditText) findViewById(R.id.wysurname);
    editctry = (EditText) findViewById(R.id.wycountry);
    psw = editps.getText().toString();
    nr= edytn.getText().toString();
    srn = editsn.getText().toString();
    ctr= editctry.getText().toString();
    sql.openToWrite();
    sql.Updater(psw, nr, srn, ctr,"iie");
    sql.close();
    startActivity(new Intent(this,UserPanel.class));
}

检查登录方法也正在关闭:

public void OkCl(View v){
    enterLog = enterLogin.getText().toString();
    enterPass = enterPassword.getText().toString();
    sqa=  new SQLiteAdapter(this);
    sqa.openToRead();
    Log.i("login",enterLog);
    Log.i("password",Login.enterPass);
    if(sqa.logineSelector(enterLog, enterPass)==true){
        Log.i("zwrocilo", "true");
        startActivity(new Intent(this,UserPanel.class));
       sqa.close();
    }
    else if (sqa.logineSelector(enterLog, enterPass)==false){
        sqa.close();
        Log.i("zwrocilo", "false");
        AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
        alertbox.setMessage("Wrong password or login");
        alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
            }
        });
        alertbox.show();
    }
}

1 个答案:

答案 0 :(得分:1)

如果colLogin是列的名称而log是值,则您的参数whereClausewhereArgs似乎搞砸了。

我认为应该是

return sqLiteDatabase.update(Usr_TABLE, cv, colLogin+"=?", new String []{log});

return sqLiteDatabase.update(Usr_TABLE, cv, colLogin+"="+log, null);

因为whereArgs替换为“?”在whereClause