diff --git a/src/zutil/db/DBConnection.java b/src/zutil/db/DBConnection.java index 1264a59..014a8d1 100644 --- a/src/zutil/db/DBConnection.java +++ b/src/zutil/db/DBConnection.java @@ -84,17 +84,17 @@ public class DBConnection{ /** * @return the last inserted id or -1 if there was an error */ - public int getLastInsertID(){ + public Object getLastInsertID(){ try{ - return exec("SELECT LAST_INSERT_ID()", new SQLResultHandler(){ - public Integer handle(Statement stmt, ResultSet result) throws SQLException { + return exec("SELECT LAST_INSERT_ID()", new SQLResultHandler(){ + public Object handleQueryResult(Statement stmt, ResultSet result) throws SQLException { if(result.next()) - return result.getInt(1); - return -1; + return result.getObject(1); + return null; } }); }catch(SQLException e){ - return -1; + return null; } } @@ -137,7 +137,7 @@ public class DBConnection{ */ public static int exec(PreparedStatement stmt) throws SQLException { return exec(stmt, new SQLResultHandler(){ - public Integer handle(Statement stmt, ResultSet result) { + public Integer handleQueryResult(Statement stmt, ResultSet result) { try { return stmt.getUpdateCount(); } catch (SQLException e) { @@ -178,7 +178,7 @@ public class DBConnection{ ResultSet result = null; try{ result = stmt.getResultSet(); - return handler.handle(stmt, result); + return handler.handleQueryResult(stmt, result); }finally{ if(result != null){ try { diff --git a/src/zutil/db/DBQueue.java b/src/zutil/db/DBQueue.java index 6e623c2..1cd6fbb 100644 --- a/src/zutil/db/DBQueue.java +++ b/src/zutil/db/DBQueue.java @@ -63,7 +63,7 @@ public class DBQueue implements Queue{ public synchronized E peek() { try { return db.exec("SELECT * FROM "+table+" LIMIT 1", new SQLResultHandler(){ - public E handle(Statement stmt, ResultSet rs) throws SQLException{ + public E handleQueryResult(Statement stmt, ResultSet rs) throws SQLException{ if (rs.next()) try { return (E) Converter.toObject(rs.getBytes("data")); @@ -83,7 +83,7 @@ public class DBQueue implements Queue{ public synchronized E poll() { try { return db.exec("SELECT * FROM "+table+" LIMIT 1", new SQLResultHandler(){ - public E handle(Statement stmt, ResultSet rs) { + public E handleQueryResult(Statement stmt, ResultSet rs) { try{ if (rs.next()) { db.exec("DELETE FROM "+table+" WHERE id="+rs.getInt("id")+" LIMIT 1"); @@ -121,7 +121,7 @@ public class DBQueue implements Queue{ public boolean contains(Object arg0) { try { return db.exec("SELECT data FROM "+table+" WHERE data='"+Converter.toBytes(arg0)+"' LIMIT 1", new SQLResultHandler(){ - public Boolean handle(Statement stmt, ResultSet rs) throws SQLException{ + public Boolean handleQueryResult(Statement stmt, ResultSet rs) throws SQLException{ return rs.next(); } }); @@ -168,7 +168,7 @@ public class DBQueue implements Queue{ public int size() { try { return db.exec("SELECT count(*) FROM "+table, new SQLResultHandler(){ - public Integer handle(Statement stmt, ResultSet rs) throws SQLException{ + public Integer handleQueryResult(Statement stmt, ResultSet rs) throws SQLException{ if (rs.next()) return rs.getInt(1); return 0; diff --git a/src/zutil/db/SQLResultHandler.java b/src/zutil/db/SQLResultHandler.java index 353f3ec..99077c6 100644 --- a/src/zutil/db/SQLResultHandler.java +++ b/src/zutil/db/SQLResultHandler.java @@ -11,5 +11,5 @@ public interface SQLResultHandler { * @param stmt is the query * @param result is the ResultSet */ - public T handle(Statement stmt, ResultSet result) throws SQLException; + public T handleQueryResult(Statement stmt, ResultSet result) throws SQLException; }