Deleting a SQLite Database File Using Java Does Not Work

These code blocks work, but ... If I use these blocks one by one, my application does not delete the database file. ( resultequal to false)

sqlite manages the part:

    // sqlite manage

        Class.forName("org.sqlite.JDBC").newInstance();            
            conn = DriverManager.getConnection("jdbc:sqlite:/"+ myDBpath);
            stmt = conn.createStatement();
    //some calculations
    stmt.close();

removal part:

    //remove this file
    boolean result = new File(myDBpath).delete();

But if I use only delete code without database operations, it works! What for? How can i avoid this?

+4
source share
1 answer

Because when you use the database connection, your sql file is used and therefore you cannot delete it.

, sql , , . , , , , , .

stmt.close();

stmt.close();
conn.close();
+1

Source: https://habr.com/ru/post/1622332/


All Articles