代碼如下
public User search(String username){
SQLiteDatabase sdb = helper.getReadableDatabase();
Cursor cursor =sdb.rawQuery("select * from user where username=?", new String[]{username});
if(cursor.moveToFirst()){
String uname=cursor.getString(cursor.getColumnIndex("username"));
String pword=cursor.getString(cursor.getColumnIndex("password"));
User user=new User(uname,pword);
return user;
}
cursor.close();
return null;
}
cursor.moveToFirst()改為cursor.next() 記得應該是next()函數的樣子