Valonqar
Valonqar

Reputation: 25

How to avoid changing database name when recompiling

I'm new to Android programming, and I'm practicing with databases.

I've written an helper and a "DataManager" class.
But when I'm trying to execute my app on the AVD emulator, I always need to change my database's name, because I always get an error.

public class DBhelper extends SQLiteOpenHelper implements DBstrings{

  public DBhelper(Context ctx){
    super(ctx,DATABASE_NAME,null,DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    String q = "create table " + DATABASE_TABLE + " ("
            + KEY_ROWID + " integer primary key, "
            + KEY_TITLE + " text not null, "
            + KEY_CONTENT + " text not null);";
    db.execSQL(q);
  }

  @Override
  public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

  }

What can I do to avoid this renaming every time?

Thank you. And sorry for my perfect english.

Upvotes: 0

Views: 57

Answers (1)

Dhananjay Sarsonia
Dhananjay Sarsonia

Reputation: 144

You don't need to change the database name every time you compile the code. If you are modifying the database schema then you can just upgrade the database version. Share the error you are getting otherwise.

Upvotes: 2

Related Questions