From c8b6ff86898f79dd356bcf3110df0390f2f20cc6 Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 21 Jan 2021 18:19:10 +0800 Subject: [PATCH] change --- .../src/test/java/TestPreparedStatement.java | 36 ------------------- .../com/taosdata/example/SubscribeDemo.java | 18 +++++----- 2 files changed, 10 insertions(+), 44 deletions(-) delete mode 100644 src/connector/jdbc/src/test/java/TestPreparedStatement.java rename src/connector/jdbc/src/test/java/TestTSDBSubscribe.java => tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java (85%) diff --git a/src/connector/jdbc/src/test/java/TestPreparedStatement.java b/src/connector/jdbc/src/test/java/TestPreparedStatement.java deleted file mode 100644 index 1edb957493..0000000000 --- a/src/connector/jdbc/src/test/java/TestPreparedStatement.java +++ /dev/null @@ -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(); - } - } - } -} diff --git a/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java similarity index 85% rename from src/connector/jdbc/src/test/java/TestTSDBSubscribe.java rename to tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java index 47acb20064..bb3712a302 100644 --- a/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java @@ -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 { @@ -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; -- GitLab