java数据库文件在chrome浏览器运行时被锁定
我的目标是获得chrome历史记录,这很好用。但我的问题是,只有在chrome浏览器运行时,才能获得“数据库文件已锁定”。 我如何解决这个问题? 我可以停止数据库浏览器吗? 这是我的代码: 公共类GetChromeHistory { 公共静态void main(字符串[]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) 个答案