Community

Hi. I'm having problems Deleting a table form my database. I write this code: try{ database.getStatement().executeUpdate("DELETE * FROM Resumen"); }catch(SQLException ex){ System.out.println("Error de SQLException (2):"+ ex); } My table is called Resumen and i want to delte all the fields. I get an error message: java.lang.RuntimeException: Database is currently locked by owner: StatementOwner object. Can someone help me?? Thank you all.
Hello! The exception will not appear if you replace your code with the following one: try{ Statement st = database.getStatement(); // Create the statement which partially locks some database objects st.execute( "DELETE * FROM table1" ); // Perform required operations database.releaseStatement( st ); // Release the statement - it unlocks all locked objects }catch(SQLException ex){ System.out.println( "Error de SQLException (2):"+ ex ); } The resaon for your problem was that you did not release the statement, so your table was locked, and you could not execute your query more than once. AnyLogic API Reference guide says: public java.sql.Statement getStatement() - The method returns statement (creates if necessary). Caller is responsible to invoke releaseStatement(Statement) after all needed operations with given statement are complete (i.e. this method locks current Database object until releaseStatement(Statement) call)