influxdb-client-java
时间: 2023-11-17 09:07:59 浏览: 203
influxdb-java
influxdb-client-java是一个InfluxDB的Java客户端,可以用于连接和操作InfluxDB数据库。你可以通过以下步骤使用它:
1. 在Maven项目中添加以下依赖:
```xml
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>2.9.0</version>
</dependency>
```
2. 创建InfluxDBClient实例:
```java
InfluxDBClient client = InfluxDBClientFactory.create("http://localhost:8086", "my-token".toCharArray());
```
3. 使用InfluxDBClient实例进行操作,例如查询数据:
```java
QueryApi queryApi = client.getQueryApi();
Flux<FluxTable> tables = queryApi.query("from(bucket:\"my-bucket\") |> range(start: 0)", "my-org");
tables.subscribe(table -> {
List<FluxRecord> records = table.getRecords();
for (FluxRecord record : records) {
System.out.println(record.getTime() + ": " + record.getValueByKey("_value"));
}
});
```
阅读全文