This commit is contained in:
zyyang 2021-01-21 18:19:10 +08:00
parent fda7313ccf
commit c8b6ff8689
2 changed files with 10 additions and 44 deletions

View File

@ -1,36 +0,0 @@
import com.taosdata.jdbc.TSDBDriver;
import com.taosdata.jdbc.TSDBPreparedStatement;
import java.sql.*;
import java.util.Properties;
public class TestPreparedStatement {
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 = DriverManager.getConnection("jdbc:TAOS://localhost:0/", 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));
}
}
resSet.close();
pstmt.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
if (null != connection) {
connection.close();
}
}
}
}

View File

@ -1,3 +1,5 @@
package com.taosdata.example;
import com.taosdata.jdbc.TSDBConnection;
import com.taosdata.jdbc.TSDBDriver;
import com.taosdata.jdbc.TSDBResultSet;
@ -6,9 +8,9 @@ import com.taosdata.jdbc.TSDBSubscribe;
import java.sql.DriverManager;
import java.util.Properties;
public class TestTSDBSubscribe {
public class SubscribeDemo {
public static TSDBConnection connectTDengine(String host, String database) throws Exception {
public static TSDBConnection getConnection(String host, String database) throws Exception {
Class.forName("com.taosdata.jdbc.TSDBDriver");
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
@ -17,7 +19,7 @@ public class TestTSDBSubscribe {
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
String cs = String.format("jdbc:TAOS://%s:0/%s", host, database);
return (TSDBConnection)DriverManager.getConnection(cs, properties);
return (TSDBConnection) DriverManager.getConnection(cs, properties);
}
public static void main(String[] args) throws Exception {
@ -50,14 +52,14 @@ public class TestTSDBSubscribe {
TSDBConnection connection = null;
TSDBSubscribe sub = null;
try {
connection = connectTDengine(host, database);
connection = getConnection(host, database);
sub = ((TSDBConnection) connection).subscribe(topic, sql, false);
int total = 0;
while(true) {
while (true) {
TSDBResultSet rs = sub.consume();
int count = 0;
while(rs.next()) {
while (rs.next()) {
count++;
}
total += count;