1 Public classMydbhelperextendsSqliteopenhelper {2 //The database file is in the SD card, you must use the fully qualified name!!! Default path in/data/data/databases/testdbinsd.sqlite, but private data cannot be seen outside-unless root. 3 Private Static FinalString sql_name = "/sdcard/wang.sqlite";//The database name. //environment.getexternalstoragedirectory (). GetPath () + "Testdbinsd.sqlite";//4 Private Static FinalString main_data_table_name = "Wang";//The table name. 5 Private Static FinalString main_data_id = "ID";//4 fields of a table6 Private Static FinalString main_data_name = "NAME";7 Private Static FinalString main_data_sex = "SEX";8 Private Static FinalString Main_data_grade = "GRADE";9 Ten //Construction Method One PublicMydbhelper (Context context) { A Super(Context, Sql_name,NULL, 1); - - This step is fine. the - @Override - Public voidonCreate (Sqlitedatabase db) { - //Build Table +String s = "CREATE TABLE person (id INTEGER PRIMARY KEY autoincrement, name VARCHAR (a), age SMALLINT);"; - Db.execsql (s); +Db.execsql ("CREATE TABLE IF not EXISTS person" + "(_id integer PRIMARY KEY autoincrement, name VARCHAR, age INTEGER, info TEXT) "); A}
This part of the problem I think has not been implemented, and later verified that it did not execute.
This part of the card for a long time, later can only find
Sqliteopenhelper of the use of the method, found
- Creates a Databasehelper object that only executes this sentence is not created or opened by the connected
- Databasehelper dbhelper = new Databasehelper (sqliteactivity. This,
- "test_yangyz_db");
- a connection is created or opened only after the Databasehelper getwritabledatabase () method or the Getreadabledatabase () method is called
Only when you open or create a connection will call Oncreat, the letter is not as good as the book, many online tutorials are .....
Android Phone Development: SQLite database can be generated, but cannot create form