int ret_val = -1;
try {
count_stmt = conn.createStatement();
count_rs = count_stmt.executeQuery(sql);
count_rs.next();
ret_val = count_rs.getInt(1);
System.
out.
println("SQLException: " + se.
getMessage());
System.
out.
println("SQLState: " + se.
getSQLState());
System.
out.
println("VendorError: " + se.
getErrorCode());
} finally {
// it is a good idea to release
// resources in a finally{} block
// in reverse-order of their creation
// if they are no-longer needed
if (count_rs != null) {
try {
count_rs.close();
count_rs = null;
}
if (count_stmt != null) {
try {
count_stmt.close();
count_stmt = null;
}
if (conn != null) {
try {
conn.close();
conn = null;
}
}
return ret_val;
}