当Chrome浏览器正在运行时,数据库文件被锁定

时间:2016-02-29 11:18:12

标签: java sqlite browser-history

我的目标是获得Chrome历史记录,这很好用。但我的问题是只有在Chrome浏览器运行时才会“锁定数据库文件”。 我该如何解决这个问题? 我可以停止数据库Chrome浏览器吗? 我的代码:     公共类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 个答案:

没有答案