Question

I'm working on a project in Java, where, I have to make modifications in my SQLite Database. I connected to it and is working pretty fine, except for this weird error.

s.executeUpdate("INSERT INTO STUDENTS VALUES('S0',11)");
...
//many statements... including queries
...
String c2="INSERT INTO STUDENTS VALUES ('S1', 2)";
s.executeUpdate(c2);
s.executeUpdate("DROP TABLE STUDENTS");

The statements s.executeUpdate("INSERT INTO STUDENTS VALUES('S0',11)"); and s.executeUpdate(c2); run perfectly and insert rows into the database. But when it comes to the statement below, I'm getting the weird Database Locked error. When I changed the query to another, it also worked pretty fine. The error comes when it reaches the ending statement. More precisely, all the queries written above, i.e., the first statement of the code here work pretty fine.

Please help me to find the bug.

Was it helpful?

Solution

I guess that the "s" variable is a Statement. Try closing the resources after you execute:

PreparedStatement updateStatement = connection.prepareStatement("INSERT INTO STUDENTS VALUES ('S1', 2)");
        try {
            updateStatement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            updateStatement.close();
        }

Do this after every call to the database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top