TDengine初搭建--第四版

TDengine初搭建--第四版,第1张

TDengine初搭建--第四版

1、客户端通讯

目前客户端通讯已经都正常

2、IDEA数据库工具通讯

目前IDEA数据库工具通讯正常,可以可视化查询相应数据

3、TDengine和MySQL双配置适配

接下来是TDengine和MySQL双配置的适配

4、简单main方法测试

如果只是测试,后续不需要考虑项目整合,那直接这样即可【注意:数据库链接、数据库名、表名等等根据自己情况调整】

4.1 代码

public class testclass {
    public static void main(String[] args) throws Exception{
        Connection conn=getConn();
        Statement stmt = conn.createStatement();
        // create database
        stmt.executeUpdate("create database if not exists epiot");
        // use database
        stmt.executeUpdate("use epiot");
        // create table
        stmt.executeUpdate("create table if not exists weather (ts timestamp, temprature int, humidity float)");
        // insert data
        int affectedRows = stmt.executeUpdate("insert into weather values(now, 23, 10.3) (now + 1s, 20, 9.3)");
        System.out.println("insert " + affectedRows + " rows.");
        // query data
        ResultSet resultSet = stmt.executeQuery("select * from weather");
        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, %sn", ts, temperature, humidity);
        }
    }

    public static Connection getConn() throws Exception{
        Class.forName("com.taosdata.jdbc.TSDBDriver");
        String jdbcUrl = "jdbc:TAOS://192.168.0.127:6030/epiot?user=root&password=admin";
        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;
    }
}

 4.2 jar包

jar包有三种方式引入:①jar包导入;②源码路径打包在引入;③pom引入

这里只讲pom引入,其它有需要网上找。


    com.taosdata.jdbc
    taos-jdbcdriver
    2.0.4

5、项目整合测试(整合MySQL和TDengine)

整合结果如下图所示(2.0.34):

源码下载路径 

 springboot-tdengine-master.zip-互联网文档类资源-CSDN文库

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5705326.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存