记在java中使用TDengine的一些坑

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;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值