The use of SQL is to insert, delete, update, query.
The first thing to know about grammar
For example, there is a table with a and B two columns in it.
Insert into table (A, B) values
Update table set a=1 where a=2
Delete from table where a=1
Delete from table
Select B, from table where a=3 order by b Desc
Once you understand the syntax, you can use statements to perform database operations.
Create the database and get the handle.
new DBHelper(this"AlarmList"); db = dbhelper.getWritableDatabase();
To operate
String"xxx";db.execSQL(sql);
Close the database
db.close();
Of course, the design form should be the first.
PackageCom.shendan.superclock;ImportAndroid.content.Context;ImportAndroid.database.sqlite.SQLiteDatabase;ImportAndroid.database.sqlite.SQLiteOpenHelper;ImportAndroid.database.sqlite.SQLiteDatabase.CursorFactory; Public class dbhelper extends sqliteopenhelper { //Database version Private Static Final intVERSION =1;//Create a new tableString sql ="CREATE table if not exists alarmlist"+"(id int primary key,time int,enable int)"; Public DBHelper(context context, String name, Cursorfactory factory,intVersion) {Super(context, name, Factory, version); } Public DBHelper(Context context,string name,intVersion) { This(Context,name,NULL, version); } Public DBHelper(Context context,string name) { This(context,name,version); }@Override Public void onCreate(Sqlitedatabase db) {db.execsql (SQL); }@Override Public void Onupgrade(Sqlitedatabase DB,intOldversion,intnewversion) {}}
Here's how to read and write a database using another method
Use of Android SQL