0

这是表格和行的样子:

public static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME +
        "(" + COLUMN_ID + " integer primary key autoincrement, " + COLUMN_INSTANT +
        " TINYINT not null, " + COLUMN_CHANCE + " int not null);";

public static final String TABLE_INSERT = "INSERT INTO " + TABLE_NAME + " (" +
        COLUMN_ID+"," + COLUMN_INSTANT +","+ COLUMN_CHANCE
        +") VALUES (" +
        "1," + "0," + "10"
        +");";

这就是我尝试更新它们的方式:

try {
        open();
        ContentValues values = new ContentValues();
        values.put(column_name, value);
        database.beginTransaction();
        database.update(MySQLiteHelper.TABLE_NAME, values, MySQLiteHelper.COLUMN_ID + " = " + whereClause,null);
        database.setTransactionSuccessful();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        database.endTransaction();
    }
    close();

前面的代码将等于这个查询:

UPDATE options SET instant = 0 WHERE _id = 1

但从未应用更改。我在更新之前和之后检查了表格,但值是相同的,有人可以提出任何建议吗?

4

1 回答 1

-1

您可以制定更新方法...这是一个示例,相应地更改列名。

public int updateDetail(String new_name,String surname) {
        ContentValues values = new ContentValues();
        values.put("name", new_name);
        return Db.update(TABLE_NAME ,values, SURNAME +"=?",new String[]{surname});
}
于 2015-08-30T10:52:50.457 回答