使用select语句锁定[SQLITE_BUSY]数据库文件 [英] Getting [SQLITE_BUSY] database file is locked with select statements

查看:213
本文介绍了使用select语句锁定[SQLITE_BUSY]数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  java.sql.SQLException:[SQLITE_BUSY]数据库文件被锁定(数据库被锁定)
在org.sqlite.DB.newSQLException(DB.java:383)
在org.sqlite.DB.newSQLException(DB.java:387)
在org.sqlite.DB.execute(DB.java:339)
在org.sqlite.PrepStmt.executeQuery(PrepStmt.java:75)
在org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery (DelegatingPreparedStatement.java:96)

我知道只有一个线程可以写入sqlite数据库,但我只是从数据库中读取数据。那么,为什么我会得到这个错误信息?



顺便说一句:我的连接池看起来像这样:

 < bean class =org.apache.commons.dbcp.BasicDataSource
destroy-method =closeid =dataSource>
< property name =driverClassNamevalue =$ {database.driverClassName}/>
< property name =urlvalue =$ {database.url}/>
< property name =usernamevalue =$ {database.username}/>
< property name =passwordvalue =$ {database.password}/>
< property name =initialSizevalue =1/>
< property name =maxActivevalue =2/>
< property name =maxIdlevalue =1/>
< property name =poolPreparedStatementsvalue =true/>
< / bean>

设置为:Java 1.6,Tomcat 7.0.34,Spring 3.2,Hibernate 3.6.9和sqlite3 3.7.2

问候
罗杰

解决方案

After一些谷歌搜索,我发现连接到SQLite时使用多个连接是不好的做法。见



http:/ /touchlabblog.tumblr.com/post/24474398246/android-sqlite-locking



将您的poolize maxactive设置为1并尝试。


If I run multiple threads against my web app I get:

java.sql.SQLException: [SQLITE_BUSY]  The database file is locked (database is locked)
    at org.sqlite.DB.newSQLException(DB.java:383)
    at org.sqlite.DB.newSQLException(DB.java:387)
    at org.sqlite.DB.execute(DB.java:339)
    at org.sqlite.PrepStmt.executeQuery(PrepStmt.java:75)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)

I do know that only one thread can write to a sqlite database but I'm only reading from the database. So why do I get this error message ?

BTW: My connection pool looks like this:

<bean class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close" id="dataSource">
    <property name="driverClassName" value="${database.driverClassName}" />
    <property name="url" value="${database.url}" />
    <property name="username" value="${database.username}" />
    <property name="password" value="${database.password}" />
    <property name="initialSize" value="1" />
    <property name="maxActive" value="2" />
    <property name="maxIdle" value="1" />
    <property name="poolPreparedStatements" value="true" />
</bean>

The setup is: Java 1.6, Tomcat 7.0.34, Spring 3.2, Hibernate 3.6.9 and sqlite3 3.7.2

Regards Roger

解决方案

After some googling I found that it is a bad practice to use multiple connections when connecting to SQLite. See

http://touchlabblog.tumblr.com/post/24474398246/android-sqlite-locking

Set your poolsize maxactive to 1 and try out.

这篇关于使用select语句锁定[SQLITE_BUSY]数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆