1.创建SQLiteOpenHelper对象,通过SQLiteOpenHelper对象调用getReadableDatabase(),getWritableDatabase()方法获得(或创建)可读,可写的数据库对象
DataBaseHelper databaseHelper = new DataBaseHelper(SQLiteActivity.this,"Test_create_db",2); //DataBaseHelper extends SQLiteOpenHelper
SQLiteDatabase db = databaseHelper.getReadableDatabase(); //调用才创建数据库
2. 数据库插入,生成ContentValues对象,通过ContentValues对象想数据库中插入数据
ContentValues value = new ContentValues();
value.put("id", 1);
value.put("name", "zhangsan");
DataBaseHelper databaseHelper = new DataBaseHelper(SQLiteActivity.this,"Test_create_db",2);
SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.insert("user", null, value);
3.更改数据
DataBaseHelper databaseHelper = new DataBaseHelper(SQLiteActivity.this,"Test_create_db",2);
SQLiteDatabase db = databaseHelper.getWritableDatabase();
ContentValues value = new ContentValues();
value.put("name", "zhangshanffeng");
db.update("user", value, "id =?", new String []{"1"});
4. 查询数据
DataBaseHelper databaseHelper = new DataBaseHelper(SQLiteActivity.this,"Test_create_db",2);
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.query("user", new String []{"id","name"}, "id=?", new String[]{"1"}, null, null, null);
while(cursor.moveToNext())
{
String name = cursor.getString(cursor.getColumnIndex("name"));
System.out.println("query-->"+name);
}
http://www.cnblogs.com/TerryBlog/archive/2010/06/12/1757166.html