Closed DraganD-Ukr closed 1 week ago
1)Is there a way of using try with resources instead of using another method in DAO just for the ResultSet and PreparedStatement?
2)If it is required then isn't it better to have the garbage collection in free connection itself rather than extrapolating it out to another method ?
public void freeConnection(Connection con){}
@Aloy-Lockness11
The helper method i meant: `/**
As i understood, we can try-with-resources because they implement AutoCloseable which automatically closes them at the end of the block. Basically what i did is just extracted the code that Michelle uses in here DAOs to Parent 'DAO' class.
I'm up for try-with-resources solution as it simplifies code and resource management
Just confirm it and i'm gonna implement try with resources across my part of code!
@Aloy-Lockness11
I assume Michelle is closing resources if they are not automatically closed. That's what that part of code does
Rogger understood
@Aloy-Lockness11 So, should we keep it or depend on Autoclose?
I have already discussed with the lecturer and she recommended us to use try with resources as it goes with standards. I have also come across this thread as well may help us decide an agreement
Than let's stick with try-with-resources
agreed
agreed on try-with-resources
I added a method that closes ResultSet, PreparedStatement and Connection objects. Since we duplicate this piece of code i want to merge it immediately, so you guys use it.