Java 如何删除SQLite数据库中的条目?
我试图使DeleteEvent()生效,但无效。我需要在哪里更改代码 这是一个Android Studio java代码Java 如何删除SQLite数据库中的条目?,java,android,sqlite,android-sqlite,Java,Android,Sqlite,Android Sqlite,我试图使DeleteEvent()生效,但无效。我需要在哪里更改代码 这是一个Android Studio java代码 public class DBStructure {enter code here public static final String DB_NAME = "EVENTS_DB"; public static final int DB_VERSION = 1; public static final String EVENT_TALE_NAME
public class DBStructure {enter code here
public static final String DB_NAME = "EVENTS_DB";
public static final int DB_VERSION = 1;
public static final String EVENT_TALE_NAME = "eventstable";
public static final String EVENT = "event";
public static final String TIME = "time";
public static final String DATE = "date";
public static final String MONTH = "month";
public static final String YEAR = "year";
}
这是我的DeleteEvent()
使用
delete()
方法不需要ContentValues
:
public void DeleteEvent(String event, String time, String date, String month, String year, SQLiteDatabase database){
database.delete(
DBStructure.EVENT_TALE_NAME,
DBStructure.EVENT + " = ? AND " + DBStructure.TIME + " = ? AND " + DBStructure.DATE + " = ? AND " +
DBStructure.MONTH + " = ? AND " + DBStructure.YEAR + " = ?",
new String[] {event, time, date, month, year}
);
}
在第二个参数中,您构造WHERE子句,3d以字符串数组的形式包含将替换占位符的参数
?
您能显示DeleteEvent()的使用代码吗?
public void DeleteEvent(String event, String time, String date, String month, String year, SQLiteDatabase database){
database.delete(
DBStructure.EVENT_TALE_NAME,
DBStructure.EVENT + " = ? AND " + DBStructure.TIME + " = ? AND " + DBStructure.DATE + " = ? AND " +
DBStructure.MONTH + " = ? AND " + DBStructure.YEAR + " = ?",
new String[] {event, time, date, month, year}
);
}