I suggest you use SQLiteOpenHelper.
It automatically takes care of creating the database if it is not available ...
code example:
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DB_VERSION = 1;
private static final String DB_NAME = "myDB.db";
public DatabaseHelper(Context ctx) {
super(ctx, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE myTable(_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER NOT NULL)";
db.execSQL(query);
db.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
...
}
}
Use it as follows:
...
DatabaseHelper helper = new DatabaseHelper(context);
SQLiteDatabase db = helper.getWritableDatabase();
...
It seems to me that itβs easier, and you donβt have to worry about whether the database already exists.
Hope this helps :)
EDIT:
... , , ... .
:
String query = "YOUR SQL STATEMENT";
db.execSQL(query);
db.close();
:)