Essentially I've (disregarding exception handling, etc.):
connection.setAutoCommit(false); Statement statement1 = connection.createStatement(); statement1.executeUpdate("..."); statement1.close(); Statement statement2 = connection.createStatement(); statement2.executeUpdate("..."); statement2.close(); connection.commit();
Basically understand properly it should not have impact because all it truly does is free of charge the assets for that GC. Especially with Derby: You need to clearly close Claims, ResultSets, and Connections whenever you no more need them. Connections to Derby are assets exterior for an application, and also the garbage collector won't close them instantly.
However does it cause any difficulties with the transaction? I do not believe the transaction depends on the Statement. Can anybody insert this?
Absolutely, you are able to close them, and you ought to.
In most cases, when a
Statement is performed, the actual datasource/database accounts for making certain effective execution. Any failures are required to lead to
SQLExceptions being tossed within the
Statement.executeXXX invocations. And then any effective execution would increase the risk for database monitoring these updates inside a temporary course. Carrying out the transaction basically guarantees the updates triggered through the claims are written to some durable store, in the temporary course. This really is frequently the situation in manyOrall databases.
Therefore, it is safe to shut a
Statement object when you no more require it, without experiencing any unwanted effects within the transaction.
Yup. Its a sensible practice and method of close statement before carrying out the transactions.