Why am I getting a SQLException: database is locked in SQLite JDBC database?

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(); // queries the database
DB.close();
// now do something with `stuff`

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

+5
3

, Java-, . :

ps aux | grep java | grep -v grep | awk '{print$2}' | xargs sudo kill -9

( PID).

, . , - , , . , , .

.

+2

java.sql.SQLException:

' SQLite Shared. .

SQLite Exclusive. .

http://www.sqlite.org/lockingv3.html '

, .

0

In my case, the problem arose from trying to update the database with Java by opening it in the SQLite Database Browser (which seems to hold the lock on db).

0
source

All Articles