Getting [SQLITE_BUSY] database file is locked with select statements Getting [SQLITE_BUSY] database file is locked with select statements sqlite sqlite

Getting [SQLITE_BUSY] database file is locked with select statements


After some googling I found that it is a bad practice to use multiple connections when connecting to SQLite. See

http://touchlabblog.tumblr.com/post/24474398246/android-sqlite-locking

Set your poolsize maxactive to 1 and try out.


There should be only ONE connection with your application.you can use this to ensure.

public class SqliteHelper {private static Connection c = null;public static Connection getConn() throws Exception {    if(c == null){    Class.forName("org.sqlite.JDBC");    c = DriverManager.getConnection("jdbc:sqlite:D:/test.db");    }    return c;    }}


Note also that this may happen if you accidentally forget to close your connection:

Connection connection;try {  Statement statement = connection.createStatement();  ResultSet resultSet = statement.executeQuery(QUERY);  if (resultSet.next()) { /* do something */ }catch (SQLException e) { /* handle exception */ }finally {  if (connection != null) {    try {      connection.close(); // <-- This is important    } catch (SQLException e) {      /* handle exception */    }  }}

While the first database connection may work well once the server is started, subsequent queries may not, depending on how the connection pool is configured.