fixed last inserted id issue

This commit is contained in:
Ziver Koc 2017-08-21 16:05:22 +02:00
parent 86ce0990c6
commit c5c135320f
2 changed files with 452 additions and 459 deletions

View file

@ -164,23 +164,16 @@ public class DBConnection implements Closeable{
* <b>NOTE:</b> Don't forget to close the PreparedStatement or it can lead to memory leaks * <b>NOTE:</b> Don't forget to close the PreparedStatement or it can lead to memory leaks
* *
* @param sql is the SQL query to run * @param sql is the SQL query to run
* @return An PreparedStatement * @return an PreparedStatement
*/ */
public PreparedStatement getPreparedStatement(String sql) throws SQLException{ public PreparedStatement getPreparedStatement(String sql) throws SQLException{
if (sql.regionMatches(true, 0, "INSERT", 0, 6))
return conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
return conn.prepareStatement(sql); return conn.prepareStatement(sql);
} }
/** /**
* <b>NOTE:</b> Don't forget to close the Statement or it can lead to memory leaks * Executes a SQL query and cleans up after itself.
*
* @return an Statement for the DB
*/
public Statement getStatement() throws SQLException{
return conn.createStatement();
}
/**
* Executes an query and cleans up after itself.
* *
* @param query is the query * @param query is the query
* @return update count or -1 if the query is not an update query * @return update count or -1 if the query is not an update query
@ -236,7 +229,7 @@ public class DBConnection implements Closeable{
* @param handler is the result handler that will be called with the output of the execution * @param handler is the result handler that will be called with the output of the execution
* @return the object from the handler * @return the object from the handler
*/ */
public static <T> T exec(PreparedStatement stmt, SQLResultHandler<T> handler) throws SQLException{ public static <T> T exec(PreparedStatement stmt, SQLResultHandler<T> handler) throws SQLException {
try{ try{
// Execute // Execute
boolean isResultSet = stmt.execute(); boolean isResultSet = stmt.execute();
@ -335,7 +328,7 @@ public class DBConnection implements Closeable{
* 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(){ public void close(){
if(pool!=null){ if(pool != null){
pool.releaseConnection(this); pool.releaseConnection(this);
conn = null; conn = null;
} }