Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.sql.SQLException: database locked

Tags:

java

sqlite

We are using sqlite056.jar in our code. While inserting into database in batch we are getting exception on line when we going to commit.

Lines of Code

<object of Connection>.commit();
<object of Connection>.setAutoCommit(true);

Exception

java.sql.SQLException: database locked
like image 869
rajkumari Avatar asked Apr 05 '10 13:04

rajkumari


3 Answers

Connection needs to be closed after each query. If any of the connections still persist. I had got the same error on Java desktop apps, now solved.

like image 50
ryu hayabuza Avatar answered Oct 20 '22 01:10

ryu hayabuza


Reading an SQLite database sets the locking state to Shared. Multiple readers can be active at the same time.

Writing to an SQLite database sets the locking state to Exclusive. No other processes can be active at that time.

You can find a detailed explanation on http://www.sqlite.org/lockingv3.html

like image 30
user247702 Avatar answered Oct 19 '22 23:10

user247702


It seems that more than one process is trying to modify the database. You can have only one connection open at any given time. More background on the problem may help us provide you with a more concrete answer.

like image 40
Bozhidar Batsov Avatar answered Oct 20 '22 00:10

Bozhidar Batsov