From 92a7bd4601f933a9d24e4dbfb8b544678924af1d Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 5 Jan 2021 14:58:11 +0800 Subject: [PATCH] change --- .../java/com/taosdata/example/JDBCDemo.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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 93f59a8982..f27659da0e 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,6 +5,7 @@ import java.util.Properties; public class JDBCDemo { private static String host; + private static String driverType; private static final String dbName = "test"; private static final String tbName = "weather"; private Connection connection; @@ -13,11 +14,15 @@ 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) { - System.out.println("Usage: java -jar JdbcDemo.jar -host "); - return; + if (host == null || driverType == null) { + printHelp(); } JDBCDemo demo = new JDBCDemo(); @@ -35,7 +40,11 @@ public class JDBCDemo { private void init() { // get connection try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); + if (driverType.equals("jni")) { + Class.forName("com.taosdata.jdbc.TSDBDriver"); + } else { + Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); + } Properties properties = new Properties(); properties.setProperty("host", host); properties.setProperty("charset", "UTF-8"); @@ -131,5 +140,10 @@ public class JDBCDemo { exuete(sql); } + private static void printHelp() { + System.out.println("Usage: java -jar JdbcDemo.jar -host -driverType "); + System.exit(0); + } + } -- GitLab