[TD-4852]<jdbcDemo.java,pom.xml> fix host,error diplay (#6929)
This commit is contained in:
parent
929a7ce4b6
commit
da3e784721
|
@ -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 {
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue