SQL Simple Statement

Source: Internet
Author: User
Tags gettext sqlite

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 (?,?)"; Db.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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.