数据库条件查询
case R.id.selectuser:
db=myDbHelper.getWritableDatabase();
String selectiontext =Et_selection.getText().toString();
//查询表user里边username和password的所有字段。
//Cursor cursor1=db.rawQuery("select username,password from user",null);
//查询表user里边用户名等于selectiontext的username和password字段。
Cursor cursor1=db.rawQuery("select username,password from user where username=?",new String[]{selectiontext});
if (cursor1.getCount()>0){ //getCount是查询到的所有条数
cursor1.moveToFirst();
showinfo.setText(cursor1.getString(0)+" "+cursor1.getString(1));
while (cursor1.moveToNext()){
showinfo.append("\n"+cursor1.getString(0)+" "+cursor1.getString(1));
}
}
else {
Toast.makeText(MainActivity.this, "查询到0条记录", Toast.LENGTH_LONG).show();
}
cursor1.close();
db.close();;
break;