Fixed some unnecessary exception

This commit is contained in:
Ziver Koc 2010-05-18 20:36:44 +00:00
parent 667a60d919
commit 06a9d49a40

View file

@ -84,21 +84,19 @@ public class DBConnection{
/** /**
* @return the last inserted id or -1 if there was an error * @return the last inserted id or -1 if there was an error
*/ */
public int getLastInsertID() throws SQLException{ public int getLastInsertID(){
Statement s = null;
try{ try{
s = conn.createStatement (); return exec("SELECT LAST_INSERT_ID()", new SQLResultHandler<Integer>(){
s.executeQuery("SELECT LAST_INSERT_ID()"); public Integer handle(Statement stmt, ResultSet result) throws SQLException {
ResultSet result = s.getResultSet(); if(result.next())
if(result.next()){
return result.getInt(1); return result.getInt(1);
}
}finally{
if(s!=null)
s.close();
}
return -1; return -1;
} }
});
}catch(SQLException e){
return -1;
}
}
/** /**
* Runs a Prepared Statement.<br> * Runs a Prepared Statement.<br>
@ -219,22 +217,21 @@ public class DBConnection{
* @return true or false depending on the validity of the connection * @return true or false depending on the validity of the connection
*/ */
public boolean valid(){ public boolean valid(){
boolean ret = true;
try { try {
conn.getMetaData(); conn.getMetaData();
ret = ret && !conn.isClosed(); return !conn.isClosed();
}catch (Exception e) { }catch (Exception e) {
return false; return false;
} }
return ret;
} }
/** /**
* Disconnects from the database or releases the connection back to the pool * Disconnects from the database or releases the connection back to the pool
*/ */
public void close() throws SQLException{ public void close(){
if(pool!=null){ if(pool!=null){
pool.releaseConnection(this); pool.releaseConnection(this);
conn = null;
} }
else{ else{
forceClose(); forceClose();