一、创建/删除表
String sql="Create table "+TABLE_NAME+"("+FIELD_ID+" integer primary key autoincrement," +FIELD_TITLE+" text );";
db.execSQL(sql);
String sql=" DROP TABLE IF EXISTS "+TABLE_NAME;
db.execSQL(sql);
二、查询
从表中查询数据(in) SELECT * FROM meta where media_id in (1,2,9);
三、插入
SQLiteDatabase db=this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(FIELD_TITLE, Title);
long row=db.insert(TABLE_NAME, null, cv);
///
String id=insertID.getText().toString();
String name=insertName.getText().toString();
//创建一个DatabaseHelper对象
DatabaseHelper dbHelper=new DatabaseHelper(Insert.this,"fantai.db3");
SQLiteDatabase db=dbHelper.getWritableDatabase();
//执行插入语句
db.execSQL("insert into user values(?,?)",new String[]{id,name});
//关闭数据库
db.close();
Toast.makeText(Insert.this, " insert success", Toast.LENGTH_SHORT).show();
四、更新
SQLiteDatabase db=this.getWritableDatabase();
String where=FIELD_ID+"=?";
String[] whereValue={Integer.toString(id)};
ContentValues cv=new ContentValues();
cv.put(FIELD_TITLE, Title);
db.update(TABLE_NAME, cv, where, whereValue);
///
String id=updateID.getText().toString();
String name=updateName.getText().toString();
//创建一个DatabaseHelper对象
DatabaseHelper dbHelper=new DatabaseHelper(Update.this,"fantai.db3");
SQLiteDatabase db=dbHelper.getWritableDatabase();
//执行更新语句
db.execSQL("update user set name=? where id=?",new String[]{name,id});
//关闭数据库
db.close();
Toast.makeText(Update.this, " Update success", Toast.LENGTH_SHORT).show();
finish();
五、删除
SQLiteDatabase db=this.getWritableDatabase();
String where=FIELD_ID+"=?";
String[] whereValue={Integer.toString(id)};
db.delete(TABLE_NAME, where, whereValue);
本文来自http://blog.csdn.net/wanglixin1999/article/details/7455407