I have two methods in my DBDriver
class to open
and close
sqlite database
as below.
private SQLiteDatabase database;
/**
* Open Database to read and write.
*
* @throws SQLException
*/
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
/**
* Close opened database.
*/
public void close() {
dbHelper.close();
}
I'm using above methods in my other class to open and close sqlite database
.
I want to identify database is open or closed. How could I do this?
if the users of your application have the ability to create many database interactions very quickly, you should use something like i have demonstrated above. but if there is minimal database interactions, i wouldn't worry about it, and just create and close the database every time.
For me the reason for "closed" was - most probably - that the framework I use (Exposed/SQLDroid) closes the database connection when it is not working. So, even when everything worked fine in the application, the database was closed at the time the Database Inspector wanted to look into it.
You can use isOpen()
to check, so in your case, that would be
database.isOpen()
just a tip, when working with Java based API (or any APIs for that matter), learning to use the documentation of the API is key. The docs will tell you which methods are available for any given class. For example, you got a instance of the class SQLiteDatabase. Checking the javadocs below
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
its pretty trivial to identify the method you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With