我想從數據庫中獲取值使用id
。但它不能獲取任何數據,它給我的語法錯誤。在android中選擇查詢錯誤
這是我的選擇功能
public Employee getStudentById(int Id) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
String selectQuery = "SELECT " +
Employee.KEY_ID + "," +
Employee.KEY_name + "," +
Employee.KEY_cast + "," +
Employee.KEY_mobile +
" FROM " + Employee.TABLE
+ " WHERE " +
Employee.KEY_ID + "=?";// It's a good practice to use parameter ?, instead of concatenate string
int iCount = 0;
Employee student = new Employee();
Cursor cursor = db.rawQuery(selectQuery, new String[]{String.valueOf(Id)});
if (cursor.moveToFirst()) {
do {
student.Employee_ID = cursor.getInt(cursor.getColumnIndex(Employee.KEY_ID));
student.name = cursor.getString(cursor.getColumnIndex(Employee.KEY_name));
student.cast = cursor.getString(cursor.getColumnIndex(Employee.KEY_cast));
student.mobile = cursor.getInt(cursor.getColumnIndex(Employee.KEY_mobile));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return student;
}
你從哪裏得到錯誤?那是什麼錯誤?編譯時使用 –
:SELECT id,name,cast,mobile FROM emp WHERE id =?在sqlite – Yogesh
最新錯誤? –