I'm trying to create an android app that will read from a existing database table and fetch words. Later I'll show the words on the activity screen. I've saved the database file in ASSETS folder but it's not working. Any help or suggestions will be very much appreciated. This is my Database class where I've tried to set the connection to the database.
public class DBManager extends SQLiteOpenHelper {
private static final String db_Word = "";
private static final String DATABASE_NAME = "SYFYB.sqlite";
private static final String DATABASE_TABLE = "WORDS";
private static final int DATABASE_VERSION = 1;
SQLiteDatabase db = null;
//public void dbCreator(Context dbContext)
//{
// try {
// db = dbContext.openOrCreateDatabase(DATABASE_NAME, DATABASE_VERSION, null);
// } catch (Exception e){
// }
//}
public DBManager(Context context)
{
super(context, "SYFYB.sqlite", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void onSelect(SQLiteDatabase db, String selectCommand){
db.execSQL(selectCommand);
}
private String[] SELECT = {"WORDS"};
private Cursor ShowDATA(SQLiteDatabase dbFromMain){
SQLiteDatabase db;
db = this.getReadableDatabase(); // ERROR
Cursor cursor = db.query("WORDS",SELECT,null,null,null,null,null);
cursor.moveToFirst();
return cursor;
}
I'm using this class from main activity as follows,
SQLiteDatabase dbFile = SQLiteDatabase.openDatabase("SYFYB.sqlite",null,SQLiteDatabase.OPEN_READONLY); //ERROR
String selectCommand = "select * from WORDS;";
DBManager dbObject = new DBManager(getApplicationContext());
dbObject.onSelect(dbFile, selectCommand);
Followings lines are shown as error Could not open Database. I've tried the Database file saved as .db and .sqlite but neither worked.
Aucun commentaire:
Enregistrer un commentaire