栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

TDengine初搭建--第四版

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文库

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/706767.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号