change
This commit is contained in:
parent
d02acc8c15
commit
a000e6d306
|
@ -75,7 +75,6 @@ public class TSDBStatement implements Statement {
|
||||||
}
|
}
|
||||||
|
|
||||||
long resultSetPointer = this.connector.getResultSet();
|
long resultSetPointer = this.connector.getResultSet();
|
||||||
|
|
||||||
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
this.connector.freeResultSet(pSql);
|
this.connector.freeResultSet(pSql);
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||||
|
|
|
@ -10,27 +10,35 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class MultiThreadsWithSameStatmentTest {
|
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
|
@Before
|
||||||
public void 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
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
Thread t1 = new Thread(() -> {
|
Thread t1 = new Thread(() -> {
|
||||||
try {
|
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()) {
|
while (resultSet.next()) {
|
||||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||||
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||||
|
@ -40,7 +48,6 @@ public class MultiThreadsWithSameStatmentTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -48,7 +55,8 @@ public class MultiThreadsWithSameStatmentTest {
|
||||||
|
|
||||||
Thread t2 = new Thread(() -> {
|
Thread t2 = new Thread(() -> {
|
||||||
try {
|
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) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue