0

在我的 Android 应用程序的数据库中,我试图更新列的特定单元格的值,但得到错误NO SUCH COLUMN

我正在我的数据库处理程序类中尝试这个查询,

public void addVote(String politicianname,int vote)
{
    ContentValues values=new ContentValues();
    values.put(KEY_TOTALVOTES, vote);
    db.update(TABLE_POLLINGVOTES, values, KEY_POLITICIANNAMES=politicianname, null);
}

这是我创建表的地方,

String CREATE_POLLINGVOTES_TABLE="CREATE TABLE pollingvotes(politiciannames TEXT, totalvotes NUMERIC)";
db.execSQL(CREATE_POLLINGVOTES_TABLE);

这是在其中添加名称的地方TABLE_POLLINGVOTES

public void addPoliticianNames() //This method is called before calling `addVote` Method
{
    deleteTable();
    String[] a = {"I","Me","Myself"};

    ContentValues values = new ContentValues();
    for (int i = 0; i < a.length; i++)
    {

        values.put(KEY_POLITICIANNAMES, a[i]);
        db.insert(TABLE_POLLINGVOTES, null, values);
    }
}

这是我的 LogCat,

10-31 05:35:45.463: E/AndroidRuntime(1169): FATAL EXCEPTION: main
10-31 05:35:45.463: E/AndroidRuntime(1169): android.database.sqlite.SQLiteException: no such column: I (code 1): , while compiling: UPDATE pollingvotes SET totalvotes=? WHERE I
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1563)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1514)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at com.example.polling.DBAdapter.addVote(DBAdapter.java:134)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at com.example.polling.VotePage.onClick(VotePage.java:42)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.view.View.performClick(View.java:4204)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.view.View$PerformClick.run(View.java:17355)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.os.Handler.handleCallback(Handler.java:725)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.os.Looper.loop(Looper.java:137)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at android.app.ActivityThread.main(ActivityThread.java:5041)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at java.lang.reflect.Method.invokeNative(Native Method)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at java.lang.reflect.Method.invoke(Method.java:511)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-31 05:35:45.463: E/AndroidRuntime(1169):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

这就是我的数据库的样子,

在此处输入图像描述

我哪里出错了,

请帮忙,

谢谢。

4

1 回答 1

3
db.update(TABLE_POLLINGVOTES, values, KEY_POLITICIANNAMES + "='" + politicianname + "'", null);

您忘记在查询中引用=符号。

于 2013-10-31T05:57:50.637 回答