1

I want to create database in android without usin the SQLiteOpenHelper Class. I want to create it using the SQLiteDatabase class.I am doing it in this way--

SQLiteDatabase sqldb;
String path="data/data/mypackagename/sample.db"

public void CreateDatabase(){
 sqldb.openOrCreateDatabase(path, null);
}

While executing it's throwing an exception that 'unable to open the databse file'. Please help me out in creating the database file using the SQLiteDatabase class.

Anubhaw
  • 5,978
  • 1
  • 29
  • 38
Prachi
  • 994
  • 5
  • 23
  • 36
  • Hi Richa give a try to my answer..... – Sujit May 26 '11 at 05:31
  • Have a look on the following url. It is a very good tutorial on creating sqlite database connection in android: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ – Sunil Kumar Sahoo May 26 '11 at 05:07
  • Deepak-- I want to create the database without using the SQLiteOpenHelper class. – Prachi May 26 '11 at 05:11

2 Answers2

2

You can not give path of your database like this ...here is the code for it..

SQLiteDatabase db;
    db = openOrCreateDatabase(
        "TestingData.db"
        , SQLiteDatabase.CREATE_IF_NECESSARY
        , null
        );

here is the link that you can refer..http://www.higherpass.com/Android/Tutorials/Accessing-Data-With-Android-Cursors/

Sujit
  • 10,512
  • 9
  • 40
  • 45
  • I tried this code but still it's throwing the same exception.'unable to open the database file'. – Prachi May 26 '11 at 05:31
  • 1
    Its working fine in my application...please check this permission in your manifest – Sujit May 26 '11 at 05:38
  • Sujit! I added this line of code in manifest file. i don't know what's going wrong. the exception is still ther. – Prachi May 26 '11 at 05:45
1

Firstly, I'm assuming your sample.db file is correctly formatted (if not, there are several very good resources for sqllite, and Deepak referenced one). Secondly, please check your permissions. If you were previously writing to your file, then you know you're fine. Just to be safe, chmod it. If that's still not it, take a look at this:

http://www.pantz.org/software/sqlite/unabletoopendbsqliteerror.html

Vinay
  • 6,204
  • 6
  • 38
  • 55