SQLite单列更新查询不起作用

时间:2018-11-27 20:04:19

标签: java android database sqlite

我的UpdateRow函数不起作用。有人可以帮忙吗?

public boolean UpdateRow(String date ,String timeOut) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL("UPDATE " + TABLE_NAME + " SET " + COL_3 + "=" + timeOut + "WHERE " + COL_1 + "=" + date);
}

谢谢。

2 个答案:

答案 0 :(得分:0)

我认为您编写的查询缺少WHERE子句和COL_1之间的空格。该行应编写如下。

db.execSQL("UPDATE " + TABLE_NAME 
    + " SET " + COL_3 + " = " + timeOut 
    + " WHERE " + COL_1 + " = " + date
);

答案 1 :(得分:0)

date前后的撇号和列之间的间隔:

db.execSQL("UPDATE " + TABLE_NAME + " SET " + COL_3 + "=" + timeOut + " WHERE " + COL_1 + "='" + date + "'");

如果timeOutTEXT,那么它也需要加撇号:

db.execSQL("UPDATE " + TABLE_NAME + " SET " + COL_3 + "='" + timeOut + "' WHERE " + COL_1 + "='" + date + "'");