我使用数据库加密/解密sqlcipher。现在我写函数巫婆检查这张卡是否存在于表卡中。当我调试我的方法总是返回false。
public boolean checkIfExistCard(String numberCard, String expirationDate) {
net.sqlcipher.database.SQLiteDatabase db = this.getReadableDatabase(DATABASE_PASSWORD);
Cursor cursor = db.query(CardColumn.CardEntry.TABLE_CARD,
new String[]{CardColumn.CardEntry.CARD_NUMBER, CardColumn.CardEntry.CARD_EXPIRATION_DATA},
CardColumn.CardEntry.CARD_NAME + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",
new String[]{numberCard, expirationDate},
null, null, null, null);
if (cursor != null) {
if (cursor.getCount() > 0) {
cursor.close();
db.close();
return true;
}
cursor.close();
db.close();
}
return false;
}
答案 0 :(得分:0)
public boolean checkIfExistCard(String numberCard, String expirationDate) {
boolean isAvailable=false;
net.sqlcipher.database.SQLiteDatabase db = this.getReadableDatabase(DATABASE_PASSWORD);
Cursor cursor = db.query(CardColumn.CardEntry.TABLE_CARD,
new String[]{CardColumn.CardEntry.CARD_NUMBER, CardColumn.CardEntry.CARD_EXPIRATION_DATA},
CardColumn.CardEntry.CARD_NAME + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",
new String[]{numberCard, expirationDate},
null, null, null, null);
if (cursor != null) {
if (cursor.getCount() > 0) {
isAvailable=true;
}
else {
isAvailable=false;
}
cursor.close();
db.close();
}
return isAvailable;
}
答案 1 :(得分:0)
也许您错过了查询中的空格。 在这一行:
CardColumn.CardEntry.CARD_NAME + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",
最后一次?标志在"之前放置了一个空格。登录。
答案 2 :(得分:0)
我解决了我的问题:)我在Cursor中犯了错误应该是CardColumn.CardEntry.CARD_NUMBER而不是CardColumn.CardEntry.CARD_NAME 它起作用:)
Cursor cursor = db.query(CardColumn.CardEntry.TABLE_CARD,
new String[]{CardColumn.CardEntry.CARD_NUMBER, CardColumn.CardEntry.CARD_EXPIRATION_DATA},
CardColumn.CardEntry.CARD_NUMBER + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",
new String[]{numberCard, expirationDate},
null, null, null, null);