Android Sqliteopenhelper instance Privatecontactsdbhelper

Source: Internet
Author: User

 Packageprivatecontact;Importandroid.content.ContentValues;ImportAndroid.content.Context;ImportAndroid.database.Cursor;Importandroid.database.sqlite.SQLiteDatabase;ImportAndroid.database.sqlite.SQLiteOpenHelper; Public classPrivatecontactsdbhelperextendsSqliteopenhelper { Public Static FinalString database_name = "Pcontacts.db";  Public Static Final intDatabase_version = 1;  Public Static FinalString table_name = "PContacts";  Public Final StaticString ID = "_id";  Public Final StaticString name = "Name";  Public Final StaticString mobile = "mobile";  Public Final StaticString email = "Email";  PublicPrivatecontactsdbhelper (Context context) {Super(Context, database_name,NULL, database_version); } @Override Public voidonCreate (Sqlitedatabase db) {String SQL= "CREATE TABLE" + table_name + "(" +ID+ "INTEGER primary key AutoIncrement," +NAME+ "text," + MOBILE + "text," + EMAIL + "text);";    Db.execsql (SQL); } @Override Public voidOnupgrade (Sqlitedatabase db,intOldversion,intnewversion) {Db.execsql ("DROP TABLE IF EXISTS" +table_name);    OnCreate (DB); }         PublicCursor Select () {sqlitedatabase db= This. Getreadabledatabase (); Cursor Cursor=db. Query (table_name,NULL,NULL,NULL,NULL,NULL,NULL); returncursor; }     Public LongInsert (String arg1, String arg2, String arg3) {Sqlitedatabase db= This. Getwritabledatabase (); /*contentvalues*/contentvalues CV=Newcontentvalues ();        Cv.put (NAME, arg1);        Cv.put (MOBILE, arg2);        Cv.put (EMAIL, ARG3); Longrow = Db.insert (table_name,NULL, CV); returnRow; }     Public voidDeleteintID) {sqlitedatabase db= This. Getwritabledatabase (); String where= ID + "=?"; String[] Wherevalue={integer.tostring (id)};    Db.delete (table_name, where, wherevalue); }     Public voidUpdateintID, string arg1, String arg2, String arg3) {Sqlitedatabase db= This. Getwritabledatabase (); String where= ID + "=?"; String[] Wherevalue={integer.tostring (id)}; Contentvalues CV=Newcontentvalues ();        Cv.put (NAME, arg1);        Cv.put (MOBILE, arg2);        Cv.put (EMAIL, ARG3);    Db.update (TABLE_NAME, CV, where, wherevalue); }}

Android Sqliteopenhelper instance Privatecontactsdbhelper

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.