0

I am new to SqlLite Database. I have created Database using SqlLite Database Browser and saved it in Android App Project Folder in path src/com/example/hello/databases/

I have also created tables already. Now, When I am trying to run code, It is showing error no such table found.
My code is as below :

public class DatabaseHandler extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 3;
    private static final String DATABASE_NAME = "db_admin";

    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    // Adding User Response When He/She attempts Questions...
    void addUserResponse(UserResponse response) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put("QId", response.getQId());
        values.put("OptionId", response.getOptionId());
        values.put("Responsedate", response.getResponseDate());

        // Inserting Row
        db.insert("tblUserResponse", null, values);
        db.close();
    }
}

Inserting values as :

        DatabaseHandler db = new DatabaseHandler(this);

        db.addUserResponse(new UserResponse("1", "1", "hello"));
        db.addUserResponse(new UserResponse("2", "1", "hello"));
        db.addUserResponse(new UserResponse("3", "3", "hello"));
        db.addUserResponse(new UserResponse("4", "2", "hello"));
14
  • where is Create Table tblUserResponse ? Commented Feb 14, 2014 at 12:57
  • @user3301551 I have already created table in Database using SqlLite Database Browser, wont it work ??? Commented Feb 14, 2014 at 12:58
  • Yes, it will. He didn't read carefully Commented Feb 14, 2014 at 12:59
  • I know. I read your question, I was answering the other user (who made my same assumption, before rereading the question) Commented Feb 14, 2014 at 13:00
  • If you want to do it this way, put the database into the assets folder of your project they create a copyDatabase() method which will copy it from the assets table and put it into the correct path that you mention. There are plenty of tutorials that show this way. Remember: If you are creating it in the SQLite browser, you need to add the locale table as well. Any tutorial should cover this. Commented Feb 14, 2014 at 13:00

1 Answer 1

0

The databases are stored in /data/data/your.app.name/databases/. So probably try running your code keeping your externally created db in this location. But I think you cant access this location if you are not rooted.

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

1 Comment

Sorry my bad I wanted to say SQLite DB's are stored in /data/data/app.package.name/databases/

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.