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 1edb957493183c407b668bd68532e83fa1a64dba..0000000000000000000000000000000000000000 --- 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 47acb200649be4c8c6af5817c2ef4c074a2a3fa0..bb3712a3024de84aea1dba0e71b47dec5e2405a5 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;