mardi 26 janvier 2016

sqlite database is locked when creating a table

I run this uber simple code:


      public static void main(String[] args) {
        Connection c = null;
        Statement stmt = null;
        try {
          Class.forName("org.sqlite.JDBC");
          c = DriverManager.getConnection("jdbc:sqlite:test.db");
          System.out.println("Opened database successfully");

          stmt = c.createStatement();
          String sql = "CREATE TABLE COMPANY " +
                  "(ID INT PRIMARY KEY     NOT NULL," +
                  " NAME           TEXT    NOT NULL, " +
                  " AGE            INT     NOT NULL, " +
                  " ADDRESS        CHAR(50enter code here), " +
                  " SALARY         REAL)";
          stmt.executeUpdate(sql);
          stmt.close();
          c.close();
        } catch ( Exception e ) {
          System.err.println( e.getClass().getName() + ": " + e.getMessage() );
          System.exit(0);
        }
        System.out.println("Table created successfully");

And I'm getting this exception

java.sql.SQLException: database is locked. It dose not really make sens it is just single connection and one operation on the DB.

Any ideas ?

Aucun commentaire:

Enregistrer un commentaire