How to check lock status and unlock if necessary for Database on Blackberry? How to check lock status and unlock if necessary for Database on Blackberry? sqlite sqlite

How to check lock status and unlock if necessary for Database on Blackberry?


I seemed to have fixed the problem. I was under the impression that if a read/write connection was open then a read-only connection could be created safely.

This doesn't seem to be the case. If I have a read/write connection open then no other connections can open until that one is finished.

I basically created one read/write connection, set a flag to identify it as open, and during my read connection use the same Database object if the flag is open, or create a read only if it's closed.

So far so good.


Sqlite does not support concurrent modification. In practice on BlackBerry, this means you can only open the database from one part of the code at a time. To maintain this one-at-a-time access, you need to close the database when you are done with it, as @AnkitRox points out.

However you also need to guard against concurrent access. Even if your code properly closes the database, it is possible for two different threads to access the database. In that case, you will need one to wait. In Java-ME this is typically accomplished through the 'synchronized' keyword, and using the same lock object for all database access.


Check properly that, you are opening and closing database before and after execution of query respectively.

Because if Database is going to open without closing it properly, then it gives errors.