A few months back I learned that when working with java.sql.connection
I needed to close PreparedStatements
and ResultSet
to prevent memory leakage, as explained here
However I recently started working with a new team that uses org.sql2o.connection
which is a nice and useful jdbc wrapper, but I noticed that they don't usually close their org.sql2o.Query
objects.
try(org.sql2o.Connection c = Sql2oObject.open()){
//...some logic
List<SomeClass> list = c.createQuery(sql).executeAndFetch(SomeClass.class);
//...some more logic
}
As you can see the query object is never explicitly closed. I think that it would be better to close the query as well as such:
try(org.sql2o.Connection c = sql2oObject.open();
org.sql2o.Query q = c.createQuery(sql); ) {
//...some logic
List<SomeClass> list = q.executeAndFetch(SomeClass.class);
//...some more logic
}
But I'm not sure if it is really necessary. If it is, then I've found a major probable leak and I will be regarded as a genius and remembered throughout the eternity. If is not, then I'm just a guy asking for an unnecessary change.
So, what do you say oh mighty SO? is it necessary to close them?