I keep getting the SQLITE_BUSY database file is locked error. I have looked on other posts, but none have solved this issue. Can't seem to figure out why this error is occurring. I know that you are only supposed to have one connection at a time, but it appears that I do only have one connection. Any ideas? Does it have something to do with the fact that Connection connection is initialized as null then reset? Thats the only thing I could think of, however if I take it away, then I am not able to close the connection in the finally block.
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();
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire