I created a static method to access my database on one of my activities but I keep getting error on opening the database.
MainActivity
public static String getStudentData() {
SQLiteDatabase sampleDB = null;
try {
//NOT WORKING
sampleDB = SQLiteDatabase.openDatabase("studentDB",null, SQLiteDatabase.CREATE_IF_NECESSARY);
//Also not working
//sampleDB = SQLiteDatabase.openOrCreateDatabase("studentDB", null);
Cursor c = sampleDB.rawQuery("SELECT * FROM student where id='1'", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
//...
}while (c.moveToNext());
}
}
c.close();
} catch (Exception se ) {
} finally {
sampleDB.close();
}
}
OtherActivity
String student = MainActivity.getStudentData();
I have been getting sqlite3_open_v2("studentDB", &handle, 6, NULL) failed
. Cant find what's wrong... I have also tried using MODE_WORLD_WRITEABLE
. Currently using MODE_PRIVATE
for database creation. Please help me out!
sampleDB = SQLiteDatabase.openOrCreateDatabase("studentDB", null);
within the activity. First time trying out static methods. Thanks! – Orchestrion