接触IoTDB也有2年了,一直记得查询效率官方说jdbc高
本文介绍IoTDB整合Druid
不用连接池整合方式
apache:
iotdb:
username: root
password: root
driver-name: org.apache.iotdb.jdbc.IoTDBDriver
url: jdbc:iotdb://192.168.0.12:6667/
initial-size: 5
min-idle: 10
max-active: 30
max-wait: 60000
remove-abandoned: true
remove-abandoned-timeout: 30
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
test-while-idle: false
test-on-borrow: false
test-on-return: false
@Slf4j
@Configuration
public class IotConfig {
@Value("${apache.iotdb.username}")
private String username;
@Value("${apache.iotdb.password}")
private String password;
@Value("${apache.iotdb.driver-name}")
private String driverName;
@Value("${apache.iotdb.url}")
private String url;
@Value("${apache.iotdb.initial-size}")
private int initialSize;
@Value("${apache.iotdb.min-idle}")
private int minIdle;
@Value("${apache.iotdb.max-active}")
private int maxActive;
@Value("${apache.iotdb.max-wait}")
private int maxWait;
@Value("${apache.iotdb.remove-abandoned}")
private boolean removeAbandoned;
@Value("${apache.iotdb.remove-abandoned-timeout}")
private int removeAbandonedTimeout;
@Value("${apache.iotdb.time-between-eviction-runs-millis}")
private int timeBetweenEvictionRunsMillis;
@Value("${apache.iotdb.min-evictable-idle-time-millis}")
private int minEvictableIdleTimeMillis;
@Value("${apache.iotdb.test-while-idle}")
private boolean testWhileIdle;
@Value("${apache.iotdb.test-on-borrow}")
private boolean testOnBorrow;
@Value("${apache.iotdb.test-on-return}")
private boolean testOnReturn;
private static DruidDataSource iotDbDataSource;
private Connection getConnection() {
if (iotDbDataSource == null) {
iotDbDataSource = new DruidDataSource();
//设置连接参数
iotDbDataSource.setUrl(url);
iotDbDataSource.setDriverClassName(driverName);
iotDbDataSource.setUsername(username);
iotDbDataSource.setPassword(password);
iotDbDataSource.setInitialSize(initialSize);
iotDbDataSource.setMinIdle(minIdle);
iotDbDataSource.setMaxActive(maxActive);
iotDbDataSource.setMaxWait(maxWait);
iotDbDataSource.setRemoveAbandoned(removeAbandoned);
iotDbDataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
iotDbDataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
iotDbDataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
//防止过期
iotDbDataSource.setTestWhileIdle(testWhileIdle);
iotDbDataSource.setTestOnBorrow(testOnBorrow);
iotDbDataSource.setTestOnReturn(testOnReturn);
}
Connection connection = null;
try {
connection = iotDbDataSource.getConnection();
} catch (SQLException e) {
e.printStackTrace();
log.error("iotDB getConnection失败: error={}", e.getMessage());
}
return connection;
}
private void close(Statement statement, Connection connection) {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (Exception e) {
log.error("iotDB close失败: error={}", e.getMessage());
}
}
}
查询整合方法,可以查看之前博客