android.database.sqlite.SQLiteException:没有这样的列:UPDATE

时间:2017-06-03 12:18:59

标签: android sql database sqlite

我的更新语句有问题。我正在尝试从我的数据库更新用户,我确信这个用户在我的数据库中,但我无法更新他。我想我的列名有问题,因为错误说:

android.database.sqlite.SQLiteException: no such column: UPDATE

但是我从未要求过这个专栏,nnn在我的计划中根本不是一个专栏。这是声明

public void changeprofiel(String id, Profiel p){

    SQLiteDatabase db = this.getWritableDatabase();


   /* ContentValues contentValues = new ContentValues();
    contentValues.put(COL_2_PROFIELEN, p.getUsername());
    contentValues.put(COL_3_PROFIELEN, p.getFirstname());
    contentValues.put(COL_4_PROFIELEN, p.getEmail());
    contentValues.put(COL_5_PROFIELEN, p.getPassword());*/

    // de insert methode geeft -1 terug als het niet gelukt is en de row value als het wel gelukt is

    System.out.println(getProfielWid(id).getId());
//    db.update(TABLE_NAME_PROFIELEN, contentValues,COL_1_PROFIELEN ="'" + id +"'",null);


    db.execSQL("UPDATE "+ TABLE_NAME_PROFIELEN + " SET "+COL_2_PROFIELEN+" = "+p.getUsername()+", " +COL_3_PROFIELEN+" = "+p.getFirstname()+", "+COL_4_PROFIELEN+" = "+p.getEmail()+", "+COL_5_PROFIELEN+" = "+p.getPassword()+
            " WHERE " + COL_1_PROFIELEN + "=" + id + "");

}

我也尝试过这种方式来填充:

" WHERE " + COL_1_PROFIELEN + "='" + id + "'");

但是他们给了我这个错误:

I/System.out: nnnnnn
E/SQLiteLog: (1) no such column: nnn
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cedri.bcv, PID: 13908
android.database.sqlite.SQLiteException: no such column: nnn (code 1): , while compiling: UPDATE profielen SET username = nnn, firstname = nnn, email = nnn, password = xxx WHERE profile_id=nnnnnn
      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
      at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
      at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
      at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
      at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
      at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1677)
      at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1608)
      at com.example.cedri.bcv.DB.DatabaseHelper.changeprofiel(DatabaseHelper.java:82)
      at com.example.cedri.bcv.Activities.MainActivity.savechanges(MainActivity.java:94)
      at com.example.cedri.bcv.Fragments.AccountFragment$1.onClick(AccountFragment.java:86)
      at android.view.View.performClick(View.java:5637)
      at android.view.View$PerformClick.run(View.java:22429)
      at android.os.Handler.handleCallback(Handler.java:751)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6121)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

我是否需要在单引号之间设置每个值?

1 个答案:

答案 0 :(得分:0)

如果列的类型为'',则需要使用单引号(text)包装值。

您的查询应如下所示:

UPDATE profielen SET username = 'nnn', firstname = 'nnn', email = 'nnn', password = 'xxx' 
WHERE profile_id='nnnnnn'