From bafaf34054b6113471021c7d6744d4f796b61fab Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 5 Aug 2011 01:55:50 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86Connection=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/druid/trunk@534 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../druid/pool/PoolableConnection.java | 110 ++++++++++++++---- 1 file changed, 86 insertions(+), 24 deletions(-) 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);