fix: scan3 bug
This commit is contained in:
parent
21cdf62293
commit
bfe2a9aac1
|
@ -527,8 +527,9 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
|
|||
|
||||
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
|
||||
throws SQLException {
|
||||
if (conn != null && !conn.isClosed()) {
|
||||
Statement stmt = conn.createStatement();
|
||||
Statement stmt = null;
|
||||
if (null != conn && !conn.isClosed()) {
|
||||
stmt = conn.createStatement();
|
||||
if (catalog == null || catalog.length() < 1) {
|
||||
catalog = conn.getCatalog();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.sql.SQLWarning;
|
|||
import java.util.List;
|
||||
|
||||
public class TSDBJNIConnector {
|
||||
static volatile Boolean isInitialized = false;
|
||||
private static volatile Boolean isInitialized = false;
|
||||
|
||||
static {
|
||||
System.loadLibrary("taos");
|
||||
|
|
|
@ -171,8 +171,7 @@ public class TSDBSubscribe {
|
|||
state = 1;
|
||||
|
||||
try {
|
||||
TSDBResultSet resultSet = consume(subscription);
|
||||
callBack.invoke(resultSet);
|
||||
callBack.invoke(consume(subscription));
|
||||
} catch (Exception e) {
|
||||
this.cancel();
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -3,10 +3,11 @@ import org.apache.commons.lang3.StringUtils;
|
|||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TestAsyncTSDBSubscribe {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws SQLException {
|
||||
String usage = "java -cp taos-jdbcdriver-1.0.3_dev-dist.jar com.taosdata.jdbc.TSDBSubscribe -db dbName -topic topicName " +
|
||||
"-tname tableName -h host";
|
||||
if (args.length < 2) {
|
||||
|
@ -38,7 +39,6 @@ public class TestAsyncTSDBSubscribe {
|
|||
}
|
||||
|
||||
Connection connection = null;
|
||||
TSDBSubscribe subscribe = null;
|
||||
long subscribId = 0;
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
|
@ -46,7 +46,7 @@ public class TestAsyncTSDBSubscribe {
|
|||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + dbName + "?user=root&password=taosdata", properties);
|
||||
String rawSql = "select * from " + tName + ";";
|
||||
subscribe = ((TSDBConnection) connection).createSubscribe();
|
||||
TSDBSubscribe subscribe = ((TSDBConnection) connection).createSubscribe();
|
||||
subscribId = subscribe.subscribe(topic, rawSql, false, 1000, new CallBack("first"));
|
||||
long subscribId2 = subscribe.subscribe("test", rawSql, false, 1000, new CallBack("second"));
|
||||
int a = 0;
|
||||
|
@ -55,6 +55,9 @@ public class TestAsyncTSDBSubscribe {
|
|||
System.err.println("cancel subscribe");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (null != connection && !connection.isClosed()) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,19 +6,20 @@ import java.util.Properties;
|
|||
|
||||
public class TestPreparedStatement {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws SQLException {
|
||||
Connection connection = null;
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "localhost");
|
||||
Connection connection = DriverManager.getConnection("jdbc:TAOS://localhost:0/?user=root&password=taosdata", properties);
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://localhost:0/?user=root&password=taosdata", properties);
|
||||
String rawSql = "select * from test.log0601";
|
||||
// String[] params = new String[]{"ts", "c1"};
|
||||
PreparedStatement pstmt = (TSDBPreparedStatement) connection.prepareStatement(rawSql);
|
||||
ResultSet resSet = pstmt.executeQuery();
|
||||
while(resSet.next()) {
|
||||
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf("%d: %s\n", i, resSet.getString(i));
|
||||
System.out.printf("%d: %s \n", i, resSet.getString(i));
|
||||
}
|
||||
}
|
||||
resSet.close();
|
||||
|
@ -27,7 +28,9 @@ public class TestPreparedStatement {
|
|||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
if (null != connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,33 @@
|
|||
import com.taosdata.jdbc.TSDBDriver;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TestTSDBDatabaseMetaData {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws SQLException {
|
||||
Connection connection = null;
|
||||
DatabaseMetaData dbMetaData = null;
|
||||
ResultSet resSet = null;
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "192.168.1.114");
|
||||
Connection connection = DriverManager.getConnection("jdbc:TAOS://192.168.1.114:0/?user=root&password=taosdata", properties);
|
||||
DatabaseMetaData dbMetaData = connection.getMetaData();
|
||||
ResultSet resSet = dbMetaData.getCatalogs();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "localhost");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://localhost:0/?user=root&password=taosdata", properties);
|
||||
dbMetaData = connection.getMetaData();
|
||||
resSet = dbMetaData.getCatalogs();
|
||||
while(resSet.next()) {
|
||||
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf("dbMetaData.getCatalogs(%d) = %s\n", i, resSet.getString(i));
|
||||
}
|
||||
}
|
||||
resSet.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (null != connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,9 +53,10 @@ public class TestTSDBSubscribe {
|
|||
subscribe = ((TSDBConnection) connection).createSubscribe();
|
||||
subscribId = subscribe.subscribe(topic, rawSql, false, 1000);
|
||||
int a = 0;
|
||||
TSDBResultSet resSet = null;
|
||||
while (true) {
|
||||
Thread.sleep(900);
|
||||
TSDBResultSet resSet = subscribe.consume(subscribId);
|
||||
resSet = subscribe.consume(subscribId);
|
||||
|
||||
while (resSet.next()) {
|
||||
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
|
||||
|
|
|
@ -37,7 +37,7 @@ public class AsyncSubscribeTest {
|
|||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
|
||||
long ts = System.currentTimeMillis();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
ts += i;
|
||||
statement.executeUpdate("insert into \" + dbName + \".\" + tName + \" values (" + ts + ", " + (100 + i) + ", " + i + ")");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -41,6 +42,7 @@ public class DatabaseMetaDataTest {
|
|||
System.out.printf("%d: %s\n", i, resultSet.getString(i));
|
||||
}
|
||||
}
|
||||
resultSet.close();
|
||||
databaseMetaData.isWrapperFor(null);
|
||||
databaseMetaData.allProceduresAreCallable();
|
||||
databaseMetaData.allTablesAreSelectable();
|
||||
|
@ -228,4 +230,11 @@ public class DatabaseMetaDataTest {
|
|||
databaseMetaData.generatedKeyAlwaysReturned();
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void close() throws SQLException {
|
||||
statement.executeUpdate("drop database " + dbName);
|
||||
statement.close();
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class PreparedStatementTest {
|
|||
|
||||
@Test
|
||||
public void testPreparedStatement() throws SQLException {
|
||||
long ts = System.currentTimeMillis();
|
||||
long ts = System.currentTimeMillis() + 20000;
|
||||
PreparedStatement saveStatement = connection
|
||||
.prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class PreparedStatementTest {
|
|||
TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection
|
||||
.prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)");
|
||||
|
||||
saveStatement.setObject(1, ts + 100);
|
||||
saveStatement.setObject(1, ts + 10000);
|
||||
saveStatement.setObject(2, 3);
|
||||
int rows = saveStatement.executeUpdate();
|
||||
assertEquals(1, rows);
|
||||
|
|
|
@ -20,7 +20,7 @@ public class SubscribeTest {
|
|||
String host = "localhost";
|
||||
String topic = "test";
|
||||
|
||||
// @Before
|
||||
@Before
|
||||
public void createDatabase() throws SQLException {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
|
@ -36,13 +36,13 @@ public class SubscribeTest {
|
|||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
|
||||
long ts = System.currentTimeMillis();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
ts += i;
|
||||
statement.executeUpdate("insert into \" + dbName + \".\" + tName + \" values (" + ts + ", " + (100 + i) + ", " + i + ")");
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void subscribe() throws Exception {
|
||||
TSDBSubscribe subscribe = null;
|
||||
long subscribId = 0;
|
||||
|
@ -68,7 +68,7 @@ public class SubscribeTest {
|
|||
}
|
||||
resSet.close();
|
||||
a++;
|
||||
if (a >= 3) {
|
||||
if (a >= 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class SubscribeTest {
|
|||
}
|
||||
}
|
||||
|
||||
// @After
|
||||
@After
|
||||
public void close() throws Exception {
|
||||
statement.executeQuery("drop database " + dbName);
|
||||
statement.close();
|
||||
|
|
Loading…
Reference in New Issue