diff --git a/src/main/java/com/alibaba/druid/pool/PoolableStatement.java b/src/main/java/com/alibaba/druid/pool/PoolableStatement.java index 62c239849f..5c3b5667f6 100644 --- a/src/main/java/com/alibaba/druid/pool/PoolableStatement.java +++ b/src/main/java/com/alibaba/druid/pool/PoolableStatement.java @@ -505,7 +505,11 @@ public class PoolableStatement extends PoolableWrapper implements Statement { @Override public final void setPoolable(boolean poolable) throws SQLException { - throw new UnsupportedOperationException(); + if (poolable) { + return; + } + + throw new SQLException("not support"); } @Override diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableStatementTest2.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableStatementTest2.java index 359bbea48e..908aa7b5ef 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableStatementTest2.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableStatementTest2.java @@ -931,4 +931,88 @@ public class PoolableStatementTest2 extends TestCase { stmt.close(); conn.close(); } + + public void test_executeUpdate_5() throws Exception { + Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement(); + + stmt.executeUpdate("SET 1", Statement.RETURN_GENERATED_KEYS); + ((PoolableStatement) stmt).getStatement().close(); + + { + SQLException error = null; + try { + stmt.executeUpdate("SET 1", Statement.RETURN_GENERATED_KEYS); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + stmt.close(); + conn.close(); + } + + public void test_executeUpdate_6() throws Exception { + Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement(); + + stmt.executeUpdate("SET 1", new String[0]); + ((PoolableStatement) stmt).getStatement().close(); + + { + SQLException error = null; + try { + stmt.executeUpdate("SET 1", new String[0]); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + stmt.close(); + conn.close(); + } + + public void test_executeUpdate_7() throws Exception { + Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement(); + + stmt.executeUpdate("SET 1", new int[0]); + ((PoolableStatement) stmt).getStatement().close(); + + { + SQLException error = null; + try { + stmt.executeUpdate("SET 1", new int[0]); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + stmt.close(); + conn.close(); + } + + + public void test_setPoolable() throws Exception { + Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement(); + + stmt.setPoolable(true); + + { + SQLException error = null; + try { + stmt.setPoolable(false); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + stmt.close(); + conn.close(); + } }