spring boot通过连接池的方式连接时序库IotDB

1、maven依赖

复制代码
<dependency>
            <groupId>org.apache.iotdb</groupId>
            <artifactId>iotdb-session</artifactId>
            <version>1.3.2</version>
        </dependency>

2、配置文件

复制代码
iotdb:
  server:
    url: localhost
    port: 6667
    name: root
    pwd: root
    maxSize: 100
    dataBaseName: root.ln

3、定义配置文件

复制代码
@Data
@Component("IotDbProperties")
@Configuration
public class IotDbProperties {
    @Value("${iotdb.server.url}")
    private String url;
    @Value("${iotdb.server.port}")
    private Integer port;
    @Value("${iotdb.server.name}")
    private String name;
    @Value("${iotdb.server.pwd}")
    private String pwd;
    @Value("${iotdb.server.maxSize}")
    private Integer maxSize;
    @Value("${iotdb.server.dataBaseName}")
    private String iotDataBaseName;

    @Bean("sessionPool")
    public ISessionPool getSessionPool() {
        return new SessionPool(this.url, this.port, this.name, this.pwd, this.maxSize);
    }
}

4、在服务层使用

通过sessionPool直接调用方法

复制代码
@Service
@Slf4j
public class IotDbServiceImpl implements IIotDbService {

    @Resource
    private ISessionPool sessionPool;

    @Value("${iotdb.server.dataBaseName}")
    private String iotDataBaseName;

注意:如果需要用到:SessionDataSetWrapper sessionDataSetWrapper查询的话,则必须调用

复制代码
sessionDataSetWrapper.close();

或者使用 try-with-resources会进行自动关闭

相关推荐
追逐时光者3 分钟前
一款使用 C# 编写专为 Windows 11 打造的文件资源管理器增强工具!
后端·.net
风象南31 分钟前
普通人用AI加持赚到的第一个100块
人工智能·后端
冰_河2 小时前
QPS从300到3100:我靠一行代码让接口性能暴涨10倍,系统性能原地起飞!!
java·后端·性能优化
JavaGuide5 小时前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
桦说编程5 小时前
从 ForkJoinPool 的 Compensate 看并发框架的线程补偿思想
java·后端·源码阅读
格砸6 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
蝎子莱莱爱打怪7 小时前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
哈密瓜的眉毛美7 小时前
零基础学Java|第三篇:DOS 命令、转义字符、注释与代码规范
后端
用户60572374873087 小时前
AI 编码助手的规范驱动开发 - OpenSpec 初探
前端·后端·程序员