diff --git a/src/main/java/com/alibaba/druid/pool/PoolableConnection.java b/src/main/java/com/alibaba/druid/pool/PoolableConnection.java index d64c7ef910..fc6e3acd04 100644 --- a/src/main/java/com/alibaba/druid/pool/PoolableConnection.java +++ b/src/main/java/com/alibaba/druid/pool/PoolableConnection.java @@ -172,8 +172,15 @@ public class PoolableConnection implements PooledConnection, Connection { } } - PreparedStatement stmt = conn.prepareStatement(sql); - + + PreparedStatement stmt = null; + + try { + stmt = conn.prepareStatement(sql); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key); @@ -202,8 +209,13 @@ public class PoolableConnection implements PooledConnection, Connection { } } - PreparedStatement stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency); - + PreparedStatement stmt = null; + try { + stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key); @@ -231,8 +243,13 @@ public class PoolableConnection implements PooledConnection, Connection { } } - PreparedStatement stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - + PreparedStatement stmt = null; + try { + stmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key); @@ -258,8 +275,13 @@ public class PoolableConnection implements PooledConnection, Connection { } } - PreparedStatement stmt = conn.prepareStatement(sql, columnIndexes); - + PreparedStatement stmt = null; + try { + stmt = conn.prepareStatement(sql, columnIndexes); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key); @@ -285,8 +307,13 @@ public class PoolableConnection implements PooledConnection, Connection { } } - PreparedStatement stmt = conn.prepareStatement(sql, columnNames); - + PreparedStatement stmt = null; + try { + stmt = conn.prepareStatement(sql, columnNames); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key); @@ -312,8 +339,13 @@ public class PoolableConnection implements PooledConnection, Connection { } } - PreparedStatement stmt = conn.prepareStatement(sql, autoGeneratedKeys); - + PreparedStatement stmt = null; + try { + stmt = conn.prepareStatement(sql, autoGeneratedKeys); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key); @@ -342,8 +374,13 @@ public class PoolableConnection implements PooledConnection, Connection { } } - CallableStatement stmt = conn.prepareCall(sql); - + CallableStatement stmt = null; + try { + stmt = conn.prepareCall(sql); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key); @@ -370,8 +407,13 @@ public class PoolableConnection implements PooledConnection, Connection { } } - CallableStatement stmt = conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - + CallableStatement stmt = null; + try { + stmt = conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key); @@ -398,8 +440,13 @@ public class PoolableConnection implements PooledConnection, Connection { } } - CallableStatement stmt = conn.prepareCall(sql, resultSetType, resultSetConcurrency); - + CallableStatement stmt = null; + try { + stmt = conn.prepareCall(sql, resultSetType, resultSetConcurrency); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key); @@ -414,8 +461,13 @@ public class PoolableConnection implements PooledConnection, Connection { public Statement createStatement() throws SQLException { checkOpen(); - Statement stmt = conn.createStatement(); - + Statement stmt = null; + try { + stmt = conn.createStatement(); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PoolableStatement poolableStatement = new PoolableStatement(this, stmt); @@ -429,8 +481,13 @@ public class PoolableConnection implements PooledConnection, Connection { throws SQLException { checkOpen(); - Statement stmt = conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); - + Statement stmt = null; + try { + stmt = conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PoolableStatement poolableStatement = new PoolableStatement(this, stmt); @@ -443,8 +500,13 @@ public class PoolableConnection implements PooledConnection, Connection { public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); - Statement stmt = conn.createStatement(resultSetType, resultSetConcurrency); - + Statement stmt = null; + try { + stmt = conn.createStatement(resultSetType, resultSetConcurrency); + } catch (SQLException ex) { + handleException(ex); + } + holder.getDataSource().initStatement(stmt); PoolableStatement poolableStatement = new PoolableStatement(this, stmt);