I have a single-threaded application that uses 3 SQLite databases in 3 different files on the local file system.
I have created a DbAdapter helper class that opens the connection to the SQLite database file. In this class I have an open method that creates the connection, and a close method that releases everything.
The 3 databases are accessed from a class that derives DbAdapter.
In my program every database access look like this:
MyDbAdapter DB = new MyDBAdapter();
int stuff = DB.getStuff(); // queries the database
DB.close();
// now do something with `stuff`
I have logged to stdout all calls to DbAdapter.open and DbAdapter.close. Everytime there’s an open(), a close() follows close by.
I also take the care to close all my Statements (which will cause the associated ResultSets to be closed aswell).
So I guess that my database accesses are clean because I’m trying to get them as short as possible, and I release all the resources as soon as I no longer need them.
Yet, I’m still getting a java.sql.SQLException: database is locked.
Is there anything that I’m not doing properly? I know I haven’t shown any code, but I’d have to post a LOT of code and it won’t be relevant. I’m just asking if I’m using the best practises here, because I think I do and I’m still getting exceptions.
This is with Java 1.6, Xerial.org’s sqlite-jdbc-3.7.2 driver, on Mac OS 10.6 x64
I noticed that I had strange Java processes that I couldn’t kill. I ran:
But those processes were still here (with same PID).
I rebooted, and the problem doesn’t appear anymore. This doesn’t make sense because I was able to make a lot of DB calls without any crash, there was just one single call that caused the exception. I don’t understand at ALL what happened, but I’m no longer having this issue.
Any real answer welcome.