java.sql.SQLException:[SQLITE_BUSY]数据库文件被锁定(数据库被锁定)

时间:2015-07-21 11:37:36

标签: java database sqlite

我不断收到SQLITE_BUSY数据库文件被锁定的错误。我查看过其他帖子,但没有人解决过这个问题。似乎无法弄清楚为什么会出现这种错误。我知道你一次只能连接一个,但似乎我只有一个连接。有任何想法吗?是否与对象Connection connection初始化为null然后重置这一事实有关?这是我唯一能想到的东西,但是如果我拿走它,那么我就无法关闭finally块中的连接。

public class GetChromeHistory
{
public static void main (String[] args) 
{

Connection connection= null;
ResultSet resultSet = null;
Statement statement = null;

try 
    {

    // We think, but are not sure, that the line below registers the sqlite drive with JDBC.
    Class.forName("org.sqlite.JDBC");
      connection = DriverManager
        .getConnection("jdbc:sqlite:db.db");
    statement = connection.createStatement();

    //problem occurs on line below, database file is locked
    resultSet = statement
        .executeQuery("SELECT * FROM urls where visit_count > 0");


    while(resultSet.next()) 
        {

        //eventually save into a set or list 
        System.out.println ("URL [" + resultSet.getString("url") + "]" +
                    ", visit count [" + resultSet.getString("visit_count") + "]");
        }
    }   

catch(Exception e) 
    {
    e.printStackTrace();
    } 

finally 
    {
    try 
        {
        resultSet.close();
        statement.close();
        connection.close();
        } 

    catch(Exception e) 
        {
        e.printStackTrace();
        }
    }
}
}

0 个答案:

没有答案