The Sqlitedatabase method generates a database file that corresponds to only one database file, or. db file, per app.
You can use a number of third-party tools to open and view the contents of the database.
Last night tried several kinds of tools, such as Navicat,sqlite3,sqlitespy, and so on, or feel sqlitespy more useful, and the volume is small, just 1.7M. There are corresponding sqlitespy in the document management. The province has been able to find the open tools of sqlite everywhere.
The previous sharedpreferences is stored in a way similar to the storage of forms in a web app.
Sqlitedatabase is similar to storing data in Oracle, except that Android is saved to the SQLite database.
Note the point:
SQLite builds tables in SQL and Oracle in different places:
In Oracle:
CREATE TABLE USERTB (_id integer primary key autoincrement, name text NOT NULL, the age integer is not null, sex text is not null )
Or
Create or Replace table USERTB (_id integer primary key autoincrement, name text NOT NULL, age integer NOT NULL, sex tex T NOT NULL)
In SQLite:
CREATE table if not exists USERTB (_id integer primary key autoincrement, name text NOT NULL, age integer NOT NULL, sex Text NOT NULL)
Be sure to add if not exists this judgment, SQLite already has the need to build the table, and when the table is built without the if not exists will be error, because can not be repeated to build the same table name table.
Mainactivity.java as follows:
Package Com.example.sqlitedatabasetest;import Android.os.bundle;import Android.app.activity;import Android.database.cursor;import Android.database.sqlite.sqlitedatabase;import Android.util.Log;public Class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate ( savedinstancestate);//Setcontentview (R.layout.activity_main);//each program has its own database by default it is independent of each other//create a database and open// Sqlitedatabase db = Openorcreatedatabase ("User.db", mode_private, NULL);//db.execsql ("CREATE table if not exists USERTB ( _id Integer PRIMARY key autoincrement, name text NOT NULL, age integer NOT null, sex text NOT null),////db.execsql ("C reate table USERTB2 (_id integer primary key, name text NOT NULL, age integer NOT null, sex text NOT null);////system . OUT.PRINTLN ("===================>");//db.execsql ("INSERT into USERTB (name,sex,age) VALUES (' Zhang San ', ' female ', 18)");// Db.execsql ("INSERT into USERTB (name,sex,age) VALUES (' John Doe ', ' female ',") ")//db.execsql (" INSERT INTO USERTB (name,sEx,age) VALUES (' Harry ', ' Male ', ') ')//system.out.println ("!!!!!!!!! 88888888234!!!!!!!! "); /cursor C = Db.rawquery ("SELECT * from USERTB", null),//if (c! = null) {//while (C.movetonext ()) {//log.i ("info", "_id:" + C.getint (C.getcolumnindex ("_id"))),//log.i ("info", "Name:" + c.getstring (C.getcolumnindex ("name")),//log.i ("info"); "," Age: "+ c.getint (C.getcolumnindex (" Age "));//LOG.I (" info "," Sex: "+ c.getstring (c.getcolumnindex (" Sex "));// LOG.I ("info", "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); /}//c.close ();//}//db.close ();//create Databasesqlitedatabase db = Openorcreatedatabase ("Wyl.db", mode_private, NULL); Db.execsql ("Create talbe if not exists wyl_table" + "(_id integer primary key autoincrement, ' + ' Name text not null,sex te XT NOT NULL "):///** * CREATE table if not exists USERTB (_id integer PRIMARY key * AutoIncrement, name text NOT NULL, AG e integer NOT NULL, sex text is not null) */db.execsql ("INSERT into wyl_table (name,sex) VALUES (' Wyl ', ' Male ')");d b.close ();} }
Sqlitedatbase of Android Storage