change
This commit is contained in:
parent
2406b9d609
commit
92a7bd4601
|
@ -5,6 +5,7 @@ import java.util.Properties;
|
||||||
|
|
||||||
public class JDBCDemo {
|
public class JDBCDemo {
|
||||||
private static String host;
|
private static String host;
|
||||||
|
private static String driverType;
|
||||||
private static final String dbName = "test";
|
private static final String dbName = "test";
|
||||||
private static final String tbName = "weather";
|
private static final String tbName = "weather";
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
@ -13,11 +14,15 @@ public class JDBCDemo {
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1)
|
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1)
|
||||||
host = args[++i];
|
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) {
|
if (host == null || driverType == null) {
|
||||||
System.out.println("Usage: java -jar JdbcDemo.jar -host <hostname>");
|
printHelp();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JDBCDemo demo = new JDBCDemo();
|
JDBCDemo demo = new JDBCDemo();
|
||||||
|
@ -35,7 +40,11 @@ public class JDBCDemo {
|
||||||
private void init() {
|
private void init() {
|
||||||
// get connection
|
// get connection
|
||||||
try {
|
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 properties = new Properties();
|
||||||
properties.setProperty("host", host);
|
properties.setProperty("host", host);
|
||||||
properties.setProperty("charset", "UTF-8");
|
properties.setProperty("charset", "UTF-8");
|
||||||
|
@ -131,5 +140,10 @@ public class JDBCDemo {
|
||||||
exuete(sql);
|
exuete(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void printHelp() {
|
||||||
|
System.out.println("Usage: java -jar JdbcDemo.jar -host <hostname> -driverType <jni|restful>");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue