未验证 提交 da3e7847 编写于 作者: X xiaolei li 提交者: GitHub

[TD-4852]<jdbcDemo.java,pom.xml> fix host,error diplay (#6929)

上级 929a7ce4
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<dependency> <dependency>
<groupId>com.taosdata.jdbc</groupId> <groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
<version>2.0.30</version> <version>2.0.31</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -43,6 +43,7 @@ public class JdbcDemo { ...@@ -43,6 +43,7 @@ public class JdbcDemo {
if (connection != null) if (connection != null)
System.out.println("[ OK ] Connection established."); System.out.println("[ OK ] Connection established.");
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
System.out.println("[ ERROR! ] Connection establish failed.");
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -68,7 +69,7 @@ public class JdbcDemo { ...@@ -68,7 +69,7 @@ public class JdbcDemo {
} }
private void insert() { 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); exuete(sql);
} }
...@@ -91,13 +92,15 @@ public class JdbcDemo { ...@@ -91,13 +92,15 @@ public class JdbcDemo {
/************************************************************************/ /************************************************************************/
private void executeQuery(String sql) { private void executeQuery(String sql) {
long start = System.currentTimeMillis();
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
long start = System.currentTimeMillis();
ResultSet resultSet = statement.executeQuery(sql); ResultSet resultSet = statement.executeQuery(sql);
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
printSql(sql, true, (end - start)); printSql(sql, true, (end - start));
printResult(resultSet); printResult(resultSet);
} catch (SQLException e) { } catch (SQLException e) {
long end = System.currentTimeMillis();
printSql(sql, false, (end - start));
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -120,12 +123,14 @@ public class JdbcDemo { ...@@ -120,12 +123,14 @@ public class JdbcDemo {
} }
private void exuete(String sql) { private void exuete(String sql) {
long start = System.currentTimeMillis();
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
long start = System.currentTimeMillis();
boolean execute = statement.execute(sql); boolean execute = statement.execute(sql);
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
printSql(sql, execute, (end - start)); printSql(sql, true, (end - start));
} catch (SQLException e) { } catch (SQLException e) {
long end = System.currentTimeMillis();
printSql(sql, false, (end - start));
e.printStackTrace(); e.printStackTrace();
} }
...@@ -137,4 +142,4 @@ public class JdbcDemo { ...@@ -137,4 +142,4 @@ public class JdbcDemo {
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册