Fixed some unnecessary exception
This commit is contained in:
parent
667a60d919
commit
06a9d49a40
1 changed files with 14 additions and 17 deletions
|
|
@ -84,20 +84,18 @@ 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);
|
return -1;
|
||||||
}
|
}
|
||||||
}finally{
|
});
|
||||||
if(s!=null)
|
}catch(SQLException e){
|
||||||
s.close();
|
return -1;
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue