//TODO:查询publicvoidquery(View view){// String sql = "select * from student where id = ?";// Cursor cursor = readableDatabase.rawQuery(sql, new String[]{"6"});// if (cursor!=null){// while (cursor.moveToNext()){// String name = cursor.getString(cursor.getColumnIndex("name"));// Toast.makeText(this, name, Toast.LENGTH_SHORT).show();// }// cursor.close();// }
Cursor cursor = readableDatabase.query("student", null,null,null,null,null,null);if(cursor!=null){while(cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex("name"));
Toast.makeText(this, name, Toast.LENGTH_SHORT).show();}
cursor.close();}}
5.删除数据
publicvoiddel(View view){// String sql = "delete from student where id = ?";// readableDatabase.execSQL(sql,new Object[]{5});
readableDatabase.delete("student","id=?",newString[]{"6"});}
6.修改数据
publicvoidupd(View view){// String sql = "update student set name = ? where id = ?";// readableDatabase.execSQL(sql,new Object[]{"张三",6});
ContentValues contentValues =newContentValues();
contentValues.put("name","呵呵");
readableDatabase.update("student",contentValues,"id=?",newString[]{"6"});}