change
This commit is contained in:
parent
fda7313ccf
commit
c8b6ff8689
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
package com.taosdata.example;
|
||||||
|
|
||||||
import com.taosdata.jdbc.TSDBConnection;
|
import com.taosdata.jdbc.TSDBConnection;
|
||||||
import com.taosdata.jdbc.TSDBDriver;
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
import com.taosdata.jdbc.TSDBResultSet;
|
import com.taosdata.jdbc.TSDBResultSet;
|
||||||
|
@ -6,9 +8,9 @@ import com.taosdata.jdbc.TSDBSubscribe;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.util.Properties;
|
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");
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||||
|
@ -17,7 +19,7 @@ public class TestTSDBSubscribe {
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
|
|
||||||
String cs = String.format("jdbc:TAOS://%s:0/%s", host, database);
|
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 {
|
public static void main(String[] args) throws Exception {
|
||||||
|
@ -50,14 +52,14 @@ public class TestTSDBSubscribe {
|
||||||
TSDBConnection connection = null;
|
TSDBConnection connection = null;
|
||||||
TSDBSubscribe sub = null;
|
TSDBSubscribe sub = null;
|
||||||
try {
|
try {
|
||||||
connection = connectTDengine(host, database);
|
connection = getConnection(host, database);
|
||||||
sub = ((TSDBConnection) connection).subscribe(topic, sql, false);
|
sub = ((TSDBConnection) connection).subscribe(topic, sql, false);
|
||||||
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
while(true) {
|
while (true) {
|
||||||
TSDBResultSet rs = sub.consume();
|
TSDBResultSet rs = sub.consume();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while(rs.next()) {
|
while (rs.next()) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
total += count;
|
total += count;
|
Loading…
Reference in New Issue