提交 c8b6ff86 编写于 作者: Z zyyang

change

上级 fda7313c
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();
}
}
}
}
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 {
......@@ -43,21 +45,21 @@ public class TestTSDBSubscribe {
}
}
if (database.isEmpty() || topic.isEmpty() || sql.isEmpty()) {
System.err.println(usage);
return;
System.err.println(usage);
return;
}
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册