0

enter image description here I create my database using sqliteadmin (version 0.8.3.2),I place this file into my asset directory and then copy this file into data/data/mypackage/databases/mydb,its ok.now when I am trying to open this file getting exception as android.database.sqlite.SQLiteException: unable to open database file,below code i am using to open the mydb.

private static final String DB_PATH = "/data/data/src.com/databases/";
private static final String DB_NAME = "mydb";
String mypath = DB_PATH + DB_NAME;

try{ 
dbBF = SQLiteDatabase.openDatabase(mypath, null, SQLiteDatabase.OPEN_READWRITE);

}catch(Exception ex)

{System.out.print("H![enter image description here][1]ere is an Exception"+ex);
}    
Cursor cur = dbBF.rawQuery("SELECT * FROM"+"myTable" , null);
aftab
  • 1,141
  • 8
  • 21
  • 40

2 Answers2

0

Your approach seems right. Do you have extension on the your database file? Like mydb.db. If you do than you should add it complete name of the file.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • thansk,my SQLite file have no any extension,when i copy from asset directory to data directory that time also i did not put any extension .. – aftab Jul 28 '11 at 14:23
  • Is it copied in that directory? Check it in your `File Explorer` in your `DDMS perspective` – Nikola Despotoski Jul 28 '11 at 14:25
  • I plugout my device ,I run my emulator in DDMS view,I run my code and I see my database file exist in data/data/package/databases/mydb directory... – aftab Jul 28 '11 at 14:43
0

I had the same problem. First please note that your database file should not be bigger than 1.2MB, and if it's, then try to split it. Second, instead of the following lines,

DBAdapter db = new DBAdapter(this);
db.openDataBase(); //Bad! db not created yet!

try to use

DBAdapter db = new DBAdapter(this);
db.createDataBase(); //needs exception handling
db.openDataBase();

I copied it from How does android access a sqlite database included in the assets folder . Anyway, it works for me. In case of any problem, let me know.

Community
  • 1
  • 1
Farid Ala
  • 668
  • 1
  • 12
  • 30