如何检查如果记录存在ImageName或不存在数据库表,我使用下面的代码检查?
// Check for Record using ImageName
public boolean Exists(String strImageName) {
SQLiteDatabase db;
db = this.getReadableDatabase(); // Read Data
Cursor cursor = db.rawQuery("select 1 from churchTable where ImageName=%s",
new String[] { strImageName });
boolean exists = (cursor.getCount() > 0);
cursor.close();
return exists;
}
答案 0 :(得分:2)
只需将%s
替换为?
,以便在那里使用strImageName
绑定参数:
Cursor cursor = db.rawQuery("select 1 from churchTable where ImageName=?",
new String[] { strImageName });