TDengine 版本 2.0.13
驱动 2.0.14 (使用2.0.13 出现 java.lang.NoSuchMethodError: setNumOfCols)
没有安装windows客户端(出现 java.lang.UnsatisfiedLinkError: no taos in java.library.path )
未修改 hosts文件(出现 FQDN异常)
step1 下载windows客户端
下载地址 https://www.taosdata.com/cn/all-downloads/
版本 TDengine-client-2.0.13.0-Windows-x64.exe
修改 C:\Windows\System32\drivers\etc\hosts
TDengine server
主机地址:192.168.32.101
hostname: wyf
hosts文件中添加
192.168.32.101 wyf
使用jdbcdemo
public static void main(String[] args) throws Exception {
Connection conn = getConn();
Statement stmt = conn.createStatement();
// create database
stmt.executeUpdate("create database if not exists db");
// use database
stmt.executeUpdate("use db");
// create table
stmt.executeUpdate("create table if not exists tb (ts timestamp, temperature int, humidity float)");
// insert data
int affectedRows = stmt.executeUpdate("insert into tb values(now, 23, 10.3) (now + 1s, 20, 9.3)");
System.out.println("insert " + affectedRows + " rows.");
// query data
ResultSet resultSet = stmt.executeQuery("select * from tb");
Timestamp ts = null;
int temperature = 0;
float humidity = 0;
while(resultSet.next()){
ts = resultSet.getTimestamp(1);
temperature = resultSet.getInt(2);
humidity = resultSet.getFloat("humidity");
System.out.printf("%s, %d, %s\n", ts, temperature, humidity);
}
}
public static Connection getConn() throws Exception{
Class.forName("com.taosdata.jdbc.TSDBDriver");
String jdbcUrl = "jdbc:TAOS://wyf:6030/log?user=root&password=taosdata";
Properties connProps = new Properties();
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
return conn;
}