我想從數據庫中選擇密碼,其中name =我在方法的參數中發送的名稱。我正在編寫數據庫的所有名稱,因此名稱在數據庫中爲100%。Android工作室SQLiteOpenHelper選擇從*其中...沒有這樣的列錯誤
,但我得到了以下錯誤:android.database.sqlite.SQLiteException: no such column: kristofer (code 1): , while compiling: SELECT * FROM login WHERE _name = kristofer
public String databasePassword(String name){
String dbString = "";
SQLiteDatabase db = getWritableDatabase();
String query = "SELECT * FROM " + TABLE_LOGIN + " WHERE "+COLUMN_NAME + " = " + name;
//Cursor point to a location in your results
Cursor c = db.rawQuery(query, null);
//Move to the first row in your results
c.moveToFirst();
while(!c.isAfterLast()){
if(c.getString(c.getColumnIndex("_password"))!=null){ //Loop through every row in a database
dbString += c.getString(c.getColumnIndex("_password"));
dbString += "\n";
}
c.moveToNext();
}
db.close();
return dbString;
}
sql的基礎知識:使用參數(最佳解決方案),或正確使用文字(不是一個好的解決方案) – Selvin