From 70bed13745e20dbdb871f45fb54c2e84db79c606 Mon Sep 17 00:00:00 2001 From: zyyang Date: Wed, 27 Jan 2021 16:07:55 +0800 Subject: [PATCH] change --- tests/examples/JDBC/JDBCDemo/pom.xml | 16 ++--- .../java/com/taosdata/example/JDBCDemo.java | 70 ++++++++----------- .../com/taosdata/example/JdbcRestfulDemo.java | 6 +- .../com/taosdata/example/SubscribeDemo.java | 1 - 4 files changed, 41 insertions(+), 52 deletions(-) diff --git a/tests/examples/JDBC/JDBCDemo/pom.xml b/tests/examples/JDBC/JDBCDemo/pom.xml index 6f0c58a821..27a03911a2 100644 --- a/tests/examples/JDBC/JDBCDemo/pom.xml +++ b/tests/examples/JDBC/JDBCDemo/pom.xml @@ -9,6 +9,14 @@ SNAPSHOT jar + + + com.taosdata.jdbc + taos-jdbcdriver + 2.0.18 + + + @@ -48,12 +56,4 @@ - - - com.taosdata.jdbc - taos-jdbcdriver - 2.0.18 - - - diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java index 0fa0059805..9a34b7d6b1 100644 --- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java @@ -5,7 +5,6 @@ import java.util.Properties; public class JDBCDemo { private static String host; - private static String driverType = "jni"; private static final String dbName = "test"; private static final String tbName = "weather"; private Connection connection; @@ -14,17 +13,10 @@ public class JDBCDemo { for (int i = 0; i < args.length; i++) { if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1) host = args[++i]; - if ("-driverType".equalsIgnoreCase(args[i]) && i < args.length - 1) { - driverType = args[++i]; - if (!"jni".equalsIgnoreCase(driverType) && !"restful".equalsIgnoreCase(driverType)) - printHelp(); - } } - if (host == null) { printHelp(); } - JDBCDemo demo = new JDBCDemo(); demo.init(); demo.createDatabase(); @@ -38,15 +30,10 @@ public class JDBCDemo { } private void init() { + final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; // get connection try { - String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; - if (driverType.equals("restful")) { - Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); - url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; - } else { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - } + Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); properties.setProperty("charset", "UTF-8"); properties.setProperty("locale", "en_US.UTF-8"); @@ -70,11 +57,39 @@ public class JDBCDemo { exuete(sql); } + private void dropTable() { + final String sql = "drop table if exists " + dbName + "." + tbName + ""; + exuete(sql); + } + + private void createTable() { + final String sql = "create table if not exists " + dbName + "." + tbName + " (ts timestamp, temperature float, humidity int)"; + exuete(sql); + } + + private void insert() { + final String sql = "insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)"; + exuete(sql); + } + private void select() { final String sql = "select * from test.weather"; executeQuery(sql); } + private void close() { + try { + if (connection != null) { + this.connection.close(); + System.out.println("connection closed."); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /************************************************************************/ + private void executeQuery(String sql) { try (Statement statement = connection.createStatement()) { long start = System.currentTimeMillis(); @@ -99,15 +114,6 @@ public class JDBCDemo { } } - private void insert() { - final String sql = "insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)"; - exuete(sql); - } - - private void createTable() { - final String sql = "create table if not exists " + dbName + "." + tbName + " (ts timestamp, temperature float, humidity int)"; - exuete(sql); - } private void printSql(String sql, boolean succeed, long cost) { System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql); @@ -125,22 +131,6 @@ public class JDBCDemo { } } - private void close() { - try { - if (connection != null) { - this.connection.close(); - System.out.println("connection closed."); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - - private void dropTable() { - final String sql = "drop table if exists " + dbName + "." + tbName + ""; - exuete(sql); - } - private static void printHelp() { System.out.println("Usage: java -jar JdbcDemo.jar -host -driverType "); System.exit(0); diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java index 91639e85f3..eedb0ba166 100644 --- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java @@ -14,9 +14,9 @@ public class JdbcRestfulDemo { String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; Properties properties = new Properties(); -// properties.setProperty("charset", "UTF-8"); -// properties.setProperty("locale", "en_US.UTF-8"); -// properties.setProperty("timezone", "UTC-8"); + properties.setProperty("charset", "UTF-8"); + properties.setProperty("locale", "en_US.UTF-8"); + properties.setProperty("timezone", "UTC-8"); Connection conn = DriverManager.getConnection(url, properties); Statement stmt = conn.createStatement(); diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java index bb3712a302..2c3a263729 100644 --- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java @@ -13,7 +13,6 @@ public class SubscribeDemo { 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); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); -- GitLab