0

When I execute the below code, I get :

"[SQLITE_BUSY] The database file is locked (database is locked)"

try {
    String query = "WITH updates(ID, newvalue) AS ( SELECT TotalStock.Sl_No, TotalStock.Price * TotalStock.Preferred_Stock  FROM TotalStock ) update TotalStock SET Total_Price=  ( SELECT newvalue FROM updates WHERE TotalStock.Sl_No = ID )";
    String query_2="select Sl_No, Item_Name, Perishable, Stock, Preferred_Stock, Total_Price from TotalStock where Stock=?";
    PreparedStatement pst=connection.prepareStatement(query);
    PreparedStatement pst_2=connection.prepareStatement(query_2);
    pst_2.setString(1, "0");
    pst.executeUpdate() ;
    ResultSet rs_2 = pst_2. executeQuery() ;
    
    table.setModel(DbUtils.resultSetToTableModel(rs_2));
} 
catch (Exception e1) {
    e1.printStackTrace();
}

SQLite connection :

Connection conn = null;

public static Connection dbConnector()
{
    try
    {
        Class.forName("org.sqlite.JDBC");
    
        Connection conn = DriverManager.getConnection("jdbc:sqlite:/Users/aditya/Downloads/EISJ/CS/IA/DATABASE/login_cred.db");
            
        return conn;
    }
    catch (Exception e)
    {
        JOptionPane.showMessageDialog(null,e);
        return null;
    }
}
1
  • "Lock" means: Some other process is using it. The fix is to find whatever other application (could be another JVM, an SQLite command line tool, etc) and close it. Commented Sep 24, 2022 at 15:14

1 Answer 1

1

There is an instance that is using the SQlite file, Check if you are not running a similar project instance that is making use of the Sqlite File.

Also ensure that you are not using external tools to inspect the sqlite file. That could block I/O operations too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.