'About function db.execSQL() in SQLite?
I am a beginner. I learn to SQLite. I don't understand function db.execSQL(DATABASE_CREATE);
private static final String DATABASE_CREATE = "create table users (_id integer primary key autoincrement, " + "name text not null);";
So function db.execSQL(). How do it word? Please help me. Thank,
Solution 1:[1]
From the Android SDK documentation for SQLiteDatabase:
execSQL(String sql): Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
In your example, to create the table, you would call db.execSQL(DATABASE_CREATE) which would execute your table create statement on your application's SQLite database.
Solution 2:[2]
this is the actual database where your data is stored. When you created your database with SQLiteOpenHelper class, it sets everything in motion to create your database but holds off until you are ready to use that database. And the way SQLiteOpenHelper knows that you are ready to use your database is when you access that database either with getReadableDatabase() or getWritableDatabase() for read and write operations respectively.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tyler Treat |
| Solution 2 | Christian Colewan |
