2

I've started Android programming recently so bear with me :)

I develop an app which has all of its content stored in database.sql file. I've implemented a subclass of SQLiteOpenHelper and added database.sql to my project assets.

public class DBHelper extends SQLiteOpenHelper
{
public DBHelper (Context ctx)
{
  super(ctx, "database.sql", null, 1);
}
}

This thing doesn't work. I just get an exception every time I try to do smth with DB :(

1
  • What's the exception being thrown? Commented Dec 12, 2009 at 23:30

2 Answers 2

4

You have 3 choices when you want to create a database locally in Android; hopefully they will support deployment directly from the APK soon. The database needs to be in a specific location :

/data/data/YOUR_PACKAGE/databases/

  1. you can download the database and write it to the database folder from a known Net location.
  2. you can create the database using code.
  3. you can copy the database from your assets folder to the database folder (doubles space required).

Also see http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

Sign up to request clarification or add additional context in comments.

Comments

1

You need to override onCreate and onUpdate as well, have a look to google's example here

7 Comments

I did that. I just didn't post it here because they are just stubs in my app.
What exception are you getting?
I get "table mytable doesn't exist"
Well that means you got an issue with your SQL queries. First check the query you wrote for creating the DB in the onCreate method. Since your using sqlite, have a look to the .sqlite file to check the state of your DB
No the problem is that an empty database is created in onCreate method instead of using my database from assets
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.