Android SQLite从表中删除行2个参数

时间:2022-09-16 14:30:30

This is my database :

这是我的数据库:

// 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";

I'm trying to create a method which takes 2 arguments and deletes a selected row from the database :

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

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

Am getting this error :

我收到此错误:

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

I know I'm doing something wrong within delete method.

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

1 个解决方案

#1


23  

Have a look at the API Docs:

看看API文档:

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

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.

You should do this:

你应该做这个:

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

#1


23  

Have a look at the API Docs:

看看API文档:

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

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.

You should do this:

你应该做这个:

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