0

I have tried to create a database in sqlite..but its not getting created.

File explorer shows no database folder in it.

Can anyone spot any error in the below given code

public DatabaseHelper(Context context) {

    super(context, databasename, null, databaseversion);
    Log.d("DatabaseHelper", "Reached Database helper");
    mContext = context;
}

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_MASTER_TABLE = "CREATE TABLE " + table_reminder_master
            + "(" + MASTER_ID + " INTEGER PRIMARY KEY ," + MASTER_TITLE
            + " TEXT," + MASTER_CONTACT_ID + " INTEGER," + MASTER_EMAIL_ID
            + " INTEGER," + MASTER_TYPE_ID + " INTEGER," + ")";
    db.execSQL(CREATE_MASTER_TABLE);
    Log.d("Table Create", "The table is created");
    Toast.makeText(mContext, "Created", Toast.LENGTH_LONG).show();

    String CREATE_CONTACT_TABLE = "CREATE TABLE " + table_contactDetails
            + "(" + CONTACT_ID + " INTEGER PRIMARY KEY ," + CONTACT_NAME
            + " TEXT," + ")";
    db.execSQL(CREATE_CONTACT_TABLE);
}

The calling class

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    db = new DatabaseHelper(this); // instantiation of database helper
    initializerMethod();
    reminder=new Reminder_Master();
    contact=new Contact_Details();
    Log.d("Main Acitivity", "Message");
    btnSave.setOnClickListener(saveHandler);
    }

Any help appreciated

1
  • You can't see db in file explorer. It's visible only to app. Can you insert and read something? Commented Apr 7, 2013 at 17:38

2 Answers 2

1

You got syntax error in your both create queries:

+ " INTEGER," + MASTER_TYPE_ID + " INTEGER," + ")";

and

+ " TEXT," + ")";

this , prior to ) should not be there.

You should have checked logcat as such errors ends with exception being thrown and logged.

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

6 Comments

Have corrected the syntax error but still...no sign of database creation...yes i'm even keeping a track on logcat..it isn't showing me any error nor is it displaying the log.d entries placed in the onCreate method on DatabaseHelper
@AbhijeetSonawane onCreate will not be called if the DB file already exists.
@CL. I have tried a number of time by changing the database version..so i guess after changing the database version the table must be recreated
The problem still persist...but still thankz a lot to u all special @WebnetMobile
@AbhijeetSonawane With a new database version, not onCreate but onUpgrade will be called.
|
0

Just creating the DatabaseHelper is not enough. You have to call getReadableDatabase() or getWriteableDatabase(). Be sure to do so on a background thread, as you do not want to do disk I/O on the main application thread.

Comments

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.