HI,
I have written a piece of Code which opens a Connection,Creates a PreparedStatment and Excutes a Query.Now i want to close the Stmts,Conns etc
Can anyone suggest which is the best way to do so.A kind of Best Practice.
For Example: 2 Ways which i have seen are
1st
-----------------------
} finally {
try {
if (objlResultSet != null) {
objlResultSet.close();
}
if (objlPreparedStatement != null) {
objlPreparedStatement.close();
}
if (objlConnection != null) {
DbUtils.closeConnection(objlConnection);
}
} catch (Exception objaException) {
error("EXCEPTION",objaException)
}
}
2nd
-----
} finally {
try {
if (objlResultSet != null) {
objlResultSet.close();
}
} catch(Exception objaException){
error("EXCEPTION");
}
try{
if (objlPreparedStatement != null) {
objlPreparedStatement.close();
}
}catch(Exception objaException){
error("EXCEPTION");
}
try{
if (objlConnection != null) {
DbUtils.closeConnection(objlConnection);
}
} catch (Exception objaException) {
error("EXCEPTION);
}
Can anyone suggest which one is better and why.Incase there is a further efficient methodology to do so .Please suggest
-Thanks-
I have written a piece of Code which opens a Connection,Creates a PreparedStatment and Excutes a Query.Now i want to close the Stmts,Conns etc
Can anyone suggest which is the best way to do so.A kind of Best Practice.
For Example: 2 Ways which i have seen are
1st
-----------------------
} finally {
try {
if (objlResultSet != null) {
objlResultSet.close();
}
if (objlPreparedStatement != null) {
objlPreparedStatement.close();
}
if (objlConnection != null) {
DbUtils.closeConnection(objlConnection);
}
} catch (Exception objaException) {
error("EXCEPTION",objaException)
}
}
2nd
-----
} finally {
try {
if (objlResultSet != null) {
objlResultSet.close();
}
} catch(Exception objaException){
error("EXCEPTION");
}
try{
if (objlPreparedStatement != null) {
objlPreparedStatement.close();
}
}catch(Exception objaException){
error("EXCEPTION");
}
try{
if (objlConnection != null) {
DbUtils.closeConnection(objlConnection);
}
} catch (Exception objaException) {
error("EXCEPTION);
}
Can anyone suggest which one is better and why.Incase there is a further efficient methodology to do so .Please suggest
-Thanks-