10

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

5 Answers 5

9

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.

Sign up to request clarification or add additional context in comments.

Comments

7

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

1 Comment

I had the same error when running an applet (that accessed a sqlite db) with appletviewer. But only when running under a 64bit jvm. Switching to a 32bit jvm worked fine (windows). Probably the 64bit driver was not compiled into the jar.
2

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.

2 Comments

can we work with multiple tables of database at same time with same connection object of database suppose i have inserted value in table 1 and at same time also inserted value in table 2 of data base with same object of data base connection.
or is database locked exception occurred due to obj Connection.commit() line
0

In my case, I forgot to add WHERE clause in my UPDATE query, and that gives "database locked" error.

Carefully check your queries.

Edit: I forgot to indicate that I have used a type of UPDATE query where I'm changing multiple attributes:

UPDATE Users SET weight = 160, desiredWeight = 145 WHERE id = 1;

3 Comments

A very old question - but thanks for attempting to answer it. In this specific case, you did not have any idea what the SQL statement in question looked like - and so suggesting that the query was UPDATE with missing WHERE comes across as guess-work. What would have been more appropriate in this case was to ask (in a comment) what the SQL query looked like - hinting that the cause might be something similar to a missing WHERE clause.
I've added edit to my post. I think it doesn't matter how long question is, people googles for this problem, like me. Greetings!
Good point. Regarding the SQL statement, I meant that the question itself did not include the SQL statement so you would not have known (without asking for it) how it looked. But good point regarding answering old questions - good point.
0

Close DB Browser (worked for me) or anything else accesses the database

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.