Select: SELECT * FROM table1 where range
Insert: INSERT INTO table1 (field1,field2) VALUES (value1,value2)
Delete: Delete from table1 where range
Updated: Update table1 set field1=value1 where range
Find: SELECT * FROM table1 where field1 like '%value1% '---the syntax of like is very subtle, check the information!
String N=name.gettext (). toString (); String E=email.gettext (). toString ();//string add= "INSERT into lgx_table (name,email) VALUES (' LGX ', ' xxx ')"; String add= "INSERT into lgx_table (Name,email) VALUES (?,?) ";d B.execsql (Add,new string[]{n,e});
Android Simple database creation and use
Package Com.example.dbdemo;import Android.content.context;import Android.database.sqlite.sqlitedatabase;import Android.database.sqlite.sqlitedatabase.cursorfactory;import Android.database.sqlite.sqliteopenhelper;public Class Databd extends Sqliteopenhelper {public Databd (context context, String name, cursorfactory factory,int version) {sup ER (context, name, Factory, version);} @Overridepublic void OnCreate (Sqlitedatabase db) {db.execsql ("CREATE Table lgx_table (_id integer PRIMARY key Autoincrement,name varchar, email varchar (50));} @Overridepublic void Onupgrade (sqlitedatabase db, int oldversion, int newversion) {}}
Package Com.example.dbdemo;import Android.app.activity;import Android.database.cursor;import Android.database.sqlite.sqlitedatabase;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;import Android.widget.textview;public class MainActivity Extends Activity {databd databd; Sqlitedatabase DB; EditText Name,email; TextView text; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main);d atabd = new Databd (This, "LGX", NULL, 2);d B = databd.getreadabledatabase (); Name= (EditText) Findviewbyid (r.id.name), email= (EditText) Findviewbyid (r.id.email); text= (TextView) Findviewbyid ( R.id.text);} public void Dbclick (View v) {switch (V.getid ()) {case r.id.add:string n=name.gettext (). toString (); String E=email.gettext (). toString ();//string add= "INSERT into lgx_table (Name,email) values(' LGX ', ' xxx '); String add= "INSERT into lgx_table (Name,email) VALUES (?,?)"; Db.execsql (Add,new string[]{n,e}); Break;case r.id.delete:break;case r.id.update:break;case R.id.select:String Select= "SELECT * from lgx_table";//db.execsql (select); Cursor cursor=db.rawquery (SELECT, null), while (Cursor.movetonext ()) {String name=cursor.getstring ( Cursor.getcolumnindex ("name")); String email=cursor.getstring (Cursor.getcolumnindex ("email")); Text.settext (name+ "" +email);} Break;default:break;}}}
SQL Simple Statement