日期:2014-05-16  浏览次数:20346 次

数据库语句小结

private SQLiteDatabase db = SQLiteDatabase.openDatabase(数据库路径, null,SQLiteDatabase.NO_LOCALIZED_COLLATORS);

1.查询全部

cursor = db.query(tablename, new String[] {id, name, age}, null, null, null, null, null);

2.根据某个固定值查询

cursor = db.query(tablename, new String[] { id,name,age}, id + "=?",new String[] { userId }, null, null, null);

3.插入

String insertSql = "INSERT INTO " + tablename + "(" + id + ","+ name + ") values ('" + userID+ "','" + username + "')";
db.execSQL(insertSql);

4.删除

db.delete(tablename, id + " = " + userID, null);

5.修改

ContentValues userMap = new ContentValues();
       userMap.put(name, username);
db.update(tablename, userMap, id + "=" + userID, null);