0

I created a database in my class like

public final String CRAZY_ALARM_DB_NAME = "CrazyDb";
public final String CRAZY_ALARM_TABLE_NAME = "CrazyTable";

alarmDB = this.openOrCreateDatabase(
    CRAZY_ALARM_DB_NAME, MODE_PRIVATE, null
);
alarmDB.execSQL("CREATE TABLE IF NOT EXISTS "
    + CRAZY_ALARM_TABLE_NAME
    +" (REQ_CODE INT(3),DAY INT(3),HOUR INT(3)"
    +",MINUTE INT(3),COUNT INT(3),REPEAT INT(3)"
    +",DAYS VARCHAR2(100),SUN INT(3),MON INT(3),"
    +"TUE INT(3),WED INT(3),THU INT(3),FRI INT(3),"
    +"SAT INT(3));"
);
cr = alarmDB.rawQuery("SELECT * FROM "
    +CRAZY_ALARM_TABLE_NAME, null
);

so i want to use this database in another class. I am also do the same thing ,i wrote "openorcreate "code in another class and also cursor.. but it gave an exception like no such table while compiling ... at cursor line..

please help me.

1
  • can you post the whole code of both class? Commented Sep 2, 2011 at 10:24

2 Answers 2

3

You should use an SQLiteOpenHelper-class to access and maintain your Database.

If you do so, you can (in whatever class you like) use the following lines to get a read or writable database:

YourSQliteOpenHelper db_con = new YourSQliteOpenHelper(getApplicationContext());
// Readable:
SQLiteDatabase db = db_con.getReadableDatabase();
// Writeable:
SQLiteDatabase db = db_con.getWritableDatabase();

A tutorial on how to use the SQLiteOpenHelper can be found here.

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

Comments

1

The best you could do is to have a database helper where you could have all these calls and which could be available and accessible by all your activities.

Moreover, you should remove and install again your app in order to be able to create the table. I have this problem sometimes.

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.