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

This commit is contained in:
xiaolei li 2021-07-31 08:07:25 +08:00 committed by GitHub
parent 929a7ce4b6
commit da3e784721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -17,7 +17,7 @@
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>2.0.30</version>
<version>2.0.31</version>
</dependency>
</dependencies>

View File

@ -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 {
}
}
}