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 1afd1a3cba2c6eb0ef4fcd32419e80d962d7c038..56e6d73a014a84280691a6a0c016cb5d3e712696 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 29716e081ecb6e93ded6c178d51be6d09cc724e4..9ed6961a365db1009dd852585944ee9bd5b00680 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(); }