java.sql.SQLException: 数据库被锁定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2578623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.sql.SQLException: database locked
提问by rajkumari
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.
我们在代码中使用 sqlite056.jar。在批量插入数据库时,我们在提交时在线收到异常。
Lines of Code
代码行
<object of Connection>.commit();
<object of Connection>.setAutoCommit(true);
Exception
例外
java.sql.SQLException: database locked
回答by Bozhidar Batsov
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.
似乎不止一个进程试图修改数据库。在任何给定时间,您只能打开一个连接。有关该问题的更多背景信息可能有助于我们为您提供更具体的答案。
回答by user247702
Reading an SQLite database sets the locking state to Shared. Multiple readers can be active at the same time.
读取 SQLite 数据库会将锁定状态设置为共享。多个阅读器可以同时处于活动状态。
Writing to an SQLite database sets the locking state to Exclusive. No other processes can be active at that time.
写入 SQLite 数据库会将锁定状态设置为独占。那时没有其他进程处于活动状态。
You can find a detailed explanation on http://www.sqlite.org/lockingv3.html
您可以在http://www.sqlite.org/lockingv3.html上找到详细说明
回答by ryu hayabuza
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.
每次查询后都需要关闭连接。如果任何连接仍然存在。我在 Java 桌面应用程序上遇到了同样的错误,现在解决了。
回答by М.Б.
In my case, I forgot to add WHERE clause in my UPDATE query, and that gives "database locked" error.
就我而言,我忘记在 UPDATE 查询中添加 WHERE 子句,这会导致“数据库锁定”错误。
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 查询:
UPDATE Users SET weight = 160, desiredWeight = 145 WHERE id = 1;
更新用户设置权重 = 160,desiredWeight = 145 WHERE id = 1;