From da3e7847212cbc3699f98e23f4e464df6a31cd5f Mon Sep 17 00:00:00 2001 From: xiaolei li <85657333+xleili@users.noreply.github.com> Date: Sat, 31 Jul 2021 08:07:25 +0800 Subject: [PATCH] [TD-4852] fix host,error diplay (#6929) --- tests/examples/JDBC/JDBCDemo/pom.xml | 2 +- .../main/java/com/taosdata/example/JdbcDemo.java | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/examples/JDBC/JDBCDemo/pom.xml b/tests/examples/JDBC/JDBCDemo/pom.xml index ca8cd24030..fed00c147b 100644 --- a/tests/examples/JDBC/JDBCDemo/pom.xml +++ b/tests/examples/JDBC/JDBCDemo/pom.xml @@ -17,7 +17,7 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.30 + 2.0.31 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 f256668dc6..d4ea5f919d 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 @@ -43,6 +43,7 @@ public class JdbcDemo { if (connection != null) System.out.println("[ OK ] Connection established."); } catch (ClassNotFoundException | SQLException e) { + System.out.println("[ ERROR! ] Connection establish failed."); e.printStackTrace(); } } @@ -68,7 +69,7 @@ public class JdbcDemo { } private void insert() { - final String sql = "insert into " + dbName + "." + tbName + " (ts, temperature, humidity) values(now, 20.5, 34)"; + final String sql = "insert into " + dbName + "." + tbName + " (ts, temperature, humidity) values(now, 20.5, 34)"; exuete(sql); } @@ -91,13 +92,15 @@ public class JdbcDemo { /************************************************************************/ private void executeQuery(String sql) { + long start = System.currentTimeMillis(); try (Statement statement = connection.createStatement()) { - long start = System.currentTimeMillis(); ResultSet resultSet = statement.executeQuery(sql); long end = System.currentTimeMillis(); printSql(sql, true, (end - start)); printResult(resultSet); } catch (SQLException e) { + long end = System.currentTimeMillis(); + printSql(sql, false, (end - start)); e.printStackTrace(); } } @@ -120,12 +123,14 @@ public class JdbcDemo { } private void exuete(String sql) { + long start = System.currentTimeMillis(); try (Statement statement = connection.createStatement()) { - long start = System.currentTimeMillis(); boolean execute = statement.execute(sql); long end = System.currentTimeMillis(); - printSql(sql, execute, (end - start)); + printSql(sql, true, (end - start)); } catch (SQLException e) { + long end = System.currentTimeMillis(); + printSql(sql, false, (end - start)); e.printStackTrace(); } @@ -137,4 +142,4 @@ public class JdbcDemo { } -} +} \ No newline at end of file -- GitLab