This commit is contained in:
zyyang 2021-01-13 16:57:33 +08:00
parent d02acc8c15
commit a000e6d306
2 changed files with 22 additions and 15 deletions

View File

@ -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));

View File

@ -10,11 +10,13 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
public class MultiThreadsWithSameStatmentTest {
private Connection conn;
private Statement stmt;
@Before
public void before() {
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");
@ -25,12 +27,18 @@ public class MultiThreadsWithSameStatmentTest {
e.printStackTrace();
}
}
}
@Before
public void before() {
}
@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();
}