fixed last inserted id issue
This commit is contained in:
parent
86ce0990c6
commit
c5c135320f
2 changed files with 452 additions and 459 deletions
|
|
@ -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
|
||||
*
|
||||
* @param sql is the SQL query to run
|
||||
* @return An PreparedStatement
|
||||
* @return an PreparedStatement
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>NOTE:</b> Don't forget to close the Statement or it can lead to memory leaks
|
||||
*
|
||||
* @return an Statement for the DB
|
||||
*/
|
||||
public Statement getStatement() throws SQLException{
|
||||
return conn.createStatement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an query and cleans up after itself.
|
||||
* Executes a SQL query and cleans up after itself.
|
||||
*
|
||||
* @param query is the 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
|
||||
* @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{
|
||||
// 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
|
||||
*/
|
||||
public void close(){
|
||||
if(pool!=null){
|
||||
if(pool != null){
|
||||
pool.releaseConnection(this);
|
||||
conn = null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue