From a000e6d3068fc662b1abcf9b8d15b09377516477 Mon Sep 17 00:00:00 2001 From: zyyang Date: Wed, 13 Jan 2021 16:57:33 +0800 Subject: [PATCH] change --- .../java/com/taosdata/jdbc/TSDBStatement.java | 1 - .../MultiThreadsWithSameStatmentTest.java | 36 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index 1afd1a3cba..56e6d73a01 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -75,7 +75,6 @@ public class TSDBStatement implements Statement { } long resultSetPointer = this.connector.getResultSet(); - if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { this.connector.freeResultSet(pSql); throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiThreadsWithSameStatmentTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiThreadsWithSameStatmentTest.java index 29716e081e..9ed6961a36 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiThreadsWithSameStatmentTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiThreadsWithSameStatmentTest.java @@ -10,27 +10,35 @@ import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; public class MultiThreadsWithSameStatmentTest { - private Connection conn; - private Statement stmt; + + + private class Service { + public Connection conn; + public Statement stmt; + + public Service() { + try { + Class.forName("com.taosdata.jdbc.TSDBDriver"); + conn = DriverManager.getConnection("jdbc:TAOS://localhost:6030/?user=root&password=taosdata"); + stmt = conn.createStatement(); + stmt.execute("create database if not exists jdbctest"); + stmt.executeUpdate("create table if not exists jdbctest.weather (ts timestamp, f1 int)"); + } catch (ClassNotFoundException | SQLException e) { + e.printStackTrace(); + } + } + } @Before public void before() { - try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - conn = DriverManager.getConnection("jdbc:TAOS://localhost:6030/?user=root&password=taosdata"); - stmt = conn.createStatement(); - stmt.execute("create database if not exists jdbctest"); - stmt.executeUpdate("create table if not exists jdbctest.weather (ts timestamp, f1 int)"); - } catch (ClassNotFoundException | SQLException e) { - e.printStackTrace(); - } } @Test public void test() { Thread t1 = new Thread(() -> { try { - ResultSet resultSet = stmt.executeQuery("select * from jdbctest.weather"); + Service service = new Service(); + ResultSet resultSet = service.stmt.executeQuery("select * from jdbctest.weather"); while (resultSet.next()) { ResultSetMetaData metaData = resultSet.getMetaData(); for (int i = 1; i <= metaData.getColumnCount(); i++) { @@ -40,7 +48,6 @@ public class MultiThreadsWithSameStatmentTest { } resultSet.close(); - } catch (SQLException e) { e.printStackTrace(); } @@ -48,7 +55,8 @@ public class MultiThreadsWithSameStatmentTest { Thread t2 = new Thread(() -> { try { - stmt.executeUpdate("insert into jdbctest.weather values(now,1)"); + Service service = new Service(); + service.stmt.executeUpdate("insert into jdbctest.weather values(now,1)"); } catch (SQLException e) { e.printStackTrace(); } -- GitLab