I have a single threaded application that uses 3 SQLite databases in 3 different files on the local file system.
I created a helper class DbAdapterthat opens a connection to a SQLite database file. In this class, I have a method openthat creates a connection, and a method closethat frees everything.
Access to 3 databases is carried out from the class that receives DbAdapter.
In my program, each access to the database is as follows:
MyDbAdapter DB = new MyDBAdapter();
int stuff = DB.getStuff();
DB.close();
I recorded stdoutall the calls DbAdapter.openand DbAdapter.close. Every time there open(), a close()follows him. I will also take care to close all mine Statement(which will cause the closure of the related ResultSet).
Therefore, I assume that my database accesses are clean, because I try to make them as short as possible, and I free up all resources as soon as I no longer need them.
However, I still get it java.sql.SQLException: database is locked.
Is there something that I am not doing right? I know that I did not show any code, but I would have to place a lot of code, and this would not be relevant. I just ask if I use the best practices here because I think I’m doing and I still get exceptions.
This is with Java 1.6, Xerial.org sqlite-jdbc-3.7.2 driver, on Mac OS 10.6 x64