The four components of Android have content Provider, which provides their own data for other applications, so, in general, Android apps do not need to provide content Provider.
1. Simple Database form Field declaration:
Mysqlname.java
Public Static Final intVERSION = 1; Public Static FinalString DBNAME = "MyDB"; /** Contact details Database*/ Public classcontacts{ Public Static FinalString tablename= "Contacts"; Public Static FinalString id= "CId";//URI of the contact person Public Static FinalString number= "Number"; Public Static FinalString name= "Name"; }
Generally a table, write an inner class, the variables of the inner class are the columns in the database. This file will do as it is written.
2. Create a database
Mysql.java
Public class Mysql extends sqliteopenhelper{
PublicMysql (Context context) {Super(Context,mysqlname.dbname,NULL, mysqlname.version); } @Override Public voidonCreate (Sqlitedatabase db) {//TODO auto-generated Method Stub /** Create a people form*/Db.execsql ("CREATE TABLE" +mysqlname.contacts.tablename+ "(" +Mysqlname.Contacts.Id+ "Integer PRIMARY key autoincrement NOT NULL," +Mysqlname.Contacts.Number+ "text," +Mysqlname.Contacts.Name+ "text);"
); }
}
In this way, the creation of the database is completed, but in addition to the creation of work, but also to provide some external methods;
3. Operation
This null, NULL null);
If you need to use the values within this CR, you need to:
if (cr!=null&&cr.getcount () >0&&= cr.getstring (Cr.getcolumnindex ( Mysqlname.Contact.Name));}
This must be movetofirst, or it will be an error.
Db.insert (Mysqlname.Contact.TableName, Mysqlname. Contact.id, values)
Db.delete (Mysqlname.Contact.TableName, mysqlname.contact.id+ "=? and" +mysqlname.contact.name+ "=?", New String[]{id, name});
New String[]{id})
Note that the above db, Cursor, after use, must be called in Time Db.close (), Cr.close ();