a. Create table
String INIT_TABLE = "CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ field1 + " TEXT, "
+ field2 + " INTEGER, "
+ field3 + " VARCHAR );" ;
db.execSQL(INIT_TABLE);
b. Delete table
try {
db.execSQL("delete from "+ tableName);
} catch (SQLException e) {
Log.e("ERROR", e.toString());
}
db.close();
c. Update table
String update = "UPDATE tableName SET field1 ='"+name+"' "
+", field2 ='"+age+"' "
+ "WHERE _ID="+id;
try {
db.execSQL(update);
} catch (SQLException e) {
Log.e("ERROR", e.toString());
}
db.close();
沒有留言:
張貼留言