0

EDIT

First activity opens a database: I used the code

LoginDbAdapter mDbHelper; // as a data member 

called

// in my onCreate() of my main activity login

mDbHelper = new LoginDbAdapter(this); 

then in my

public void onResume(){
    mDbHelper.open(); // opens only when the activity is resumed
    super.onResume();
}

then I do the same thing above in my second activity to add a user. This worked.

My issue is as follows: **How do i open a link to a second table in my database to access

a users information only. And where do i close it. **

UPDATE

an alternative way that works much better is initializing my DbAdapter in the onResume and then calling DbAdapter.open(); only when i need access to the db and closing it right after the work is done with DbAdapter.close();

note: it is also important to call startManagingCursor(cursor); and stopManagingCursor(cursor);

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
kandroidj
  • 13,784
  • 5
  • 64
  • 76

4 Answers4

0

in your Activity

mDbHelper= new DatabaseAdapter(this);

and in your insert method of DatabaseAdapter class

SQLiteDatabase db = this.getWritableDatabase();

and at last in your insert method call db.close();

Hardik Nadiyapara
  • 2,436
  • 2
  • 17
  • 24
0

Might these helps:

find these where you getting writeable permission like these::

SQLiteDatabase db=this.getWritableDatabase();

Now wat you need to do iz::

db.insert(TABLE, null, values);
db.close();//put these after inserting your database;

You need to go in to your DATABASEADAPTER class then close the database connection after insertion as per above code

Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
  • not quite working, should i only open my database inside the dbadapter? for example should i only be initializing the dbadapter and using the insert stuff if i already have a method that opens the database in my dbadapter? – kandroidj Aug 22 '12 at 14:13
  • if you have method tht opens up database connection then you should close it after insertion. Using some method which closes database connection or close it directly like these : 'db.close();' – Vikalp Patel Aug 22 '12 at 14:19
  • I will be posting my full code for you to get a better idea, but now I am not even calling open on anything other than a cursor from my login page. And i am still getting the error. Maybe you can help me clean up my code. . . posting in five minutes. Thanks – kandroidj Aug 22 '12 at 14:21
0

You need to Edit these line inside your LoginDbAdapter inside close() method;

public class LoginDbAdapter
 {
   // close the database
     public void close(){
     if(mDbHelper != null){
      mDbHelper.close();
       mDb.close;//insert these line ;these close sqlitedatabase;
       }

    }

   }
Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
-1

give the command to close inside a try{} catch{}

Anoop
  • 993
  • 6
  • 16