10

这是我的数据库:

// the names for database columns
    public final static String TABLE_NAME = "vremena";
    public final static String TABLE_COLUMN_ID = "_id";
    public final static String TABLE_COLUMN_ONE = "dan";
    public final static String TABLE_COLUMN_TWO = "vrijeme";

我正在尝试创建一个采用 2 个参数并从数据库中删除选定行的方法:

public void delete(String dan, int vrijeme){
    db.delete(TABLE_NAME, TABLE_COLUMN_ONE+"="+dan, TABLE_COLUMN_TWO+"="+vrijeme);
    }

收到此错误:

The method delete(String, String, String[]) in the type SQLiteDatabase is not applicable for the arguments (String, String, String)

我知道我在删除方法中做错了什么。

4

1 回答 1

27

查看 API 文档:

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

delete(String table, String whereClause, String[] whereArgs)
Convenience method for deleting rows in the database.

你应该做这个:

public void delete(String dan, int vrijeme){
    db.delete(TABLE_NAME, 
            TABLE_COLUMN_ONE + " = ? AND " + TABLE_COLUMN_TWO + " = ?", 
            new String[] {dan, vrijeme+""});
}
于 2013-03-20T12:33:30.217 回答