0

I'm using a servlet on an Apache Tomcat server to write and read data to/from a database via JDBC. All info received is correct, but after first read/write from/to the database, the database file is getting locked. Here's a code snippet:

        Class.forName("org.sqlite.JDBC");
        Connection conn = DriverManager.getConnection(path);
        conn.setAutoCommit(false);
        Statement stat = conn.createStatement();
        String req = "select * from login where username=\""+username+"\" and password=\""+password+"\"";
        System.out.println(req);
        ResultSet rs2 = stat.executeQuery(req);
        conn.setAutoCommit(true);
        System.out.println(rs2.getString("rights"));
        int rights = Integer.parseInt(rs2.getString("rights"));
        rs2.close();
        stat.close();
        conn.close();

The database file gets locked and stays accessed and locked if I close the connection.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
MonsterDruide1
  • 347
  • 3
  • 15
  • Possible duplicate of https://stackoverflow.com/q/8511901/266374 edit: Whoops, that's C#. But maybe it's still a GC issue in Java? – Thomas Kelley Aug 30 '18 at 16:48
  • wyh do you set `conn.setAutoCommit(false);` before query and `conn.setAutoCommit(true);` after query? – guleryuz Aug 30 '18 at 20:49
  • I've read a couple of instructions about that, in most of them is it done like this. – MonsterDruide1 Aug 31 '18 at 04:10
  • If I remove these two commands, it doesn't work either. – MonsterDruide1 Aug 31 '18 at 04:24
  • Using sqlite from a web application is a bad idea; it doesn't really support multiple connections (or at least AFAIK, the JDBC uses a variant that doesn't support that and requires exclusive access for write). Use a 'real' database. – Mark Rotteveel Aug 31 '18 at 09:21

1 Answers1

0

I found the solution, or my mistake: I exported the .war file to the wrong directory. Thanks for all help!

MonsterDruide1
  • 347
  • 3
  • 15