激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - java使用influxDB數(shù)據(jù)庫(kù)的詳細(xì)代碼

java使用influxDB數(shù)據(jù)庫(kù)的詳細(xì)代碼

2021-05-21 10:48java開(kāi)發(fā)鼻祖 Java教程

這篇文章主要為大家介紹了java使用influxDB數(shù)據(jù)庫(kù)的詳細(xì)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java使用influxdb數(shù)據(jù)庫(kù)的具體代碼,供大家參考,具體內(nèi)容如下

1.pom.xml中導(dǎo)入jar包依賴(lài)

?
1
2
3
4
5
6
<!-- 引入influxdb依賴(lài)  -->
 <dependency>
  <groupid>org.influxdb</groupid>
  <artifactid>influxdb-java</artifactid>
  <version>2.5</version>
 </dependency>

2.編寫(xiě)influxdb工具類(lèi):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.hontye.parameter.util;
 
import org.influxdb.influxdb;
import org.influxdb.influxdbfactory;
import org.influxdb.dto.point;
import org.influxdb.dto.point.builder;
import org.influxdb.dto.query;
import org.influxdb.dto.queryresult;
import java.util.map;
 
/**
 * 時(shí)序數(shù)據(jù)庫(kù) influxdb 連接
 * @author dai_lw
 *
 */
public class influxdbutil {
 
  private static string openurl = "http://127.0.0.1:8086";//連接地址
  private static string username = "root";//用戶名
  private static string password = "root";//密碼
  private static string database = "paramter_db";//數(shù)據(jù)庫(kù)
  private static string measurement = "tw_parameter_tb";//表名
 
  private influxdb influxdb;
 
 
  public influxdbutil(string username, string password, string openurl, string database){
    this.username = username;
    this.password = password;
    this.openurl = openurl;
    this.database = database;
  }
 
  public static influxdbutil setup(){
    //創(chuàng)建 連接
    influxdbutil influxdbutil = new influxdbutil(username, password, openurl, database);
 
    influxdbutil.influxdbbuild();
 
    influxdbutil.createretentionpolicy();
 
//   influxdb.deletedb(database);
//   influxdb.createdb(database);
    return influxdbutil;
  }
 
  /**連接時(shí)序數(shù)據(jù)庫(kù);獲得influxdb**/
  public influxdb influxdbbuild(){
    if(influxdb == null){
      influxdb = influxdbfactory.connect(openurl, username, password);
      influxdb.createdatabase(database);
    }
    return influxdb;
  }
 
  /**
   * 設(shè)置數(shù)據(jù)保存策略
   * defalut 策略名 /database 數(shù)據(jù)庫(kù)名/ 30d 數(shù)據(jù)保存時(shí)限30天/ 1 副本個(gè)數(shù)為1/ 結(jié)尾default 表示 設(shè)為默認(rèn)的策略
   */
  public void createretentionpolicy(){
    string command = string.format("create retention policy \"%s\" on \"%s\" duration %s replication %s default",
        "defalut", database, "30d", 1);
    this.query(command);
  }
 
  /**
   * 查詢(xún)
   * @param command 查詢(xún)語(yǔ)句
   * @return
   */
  public queryresult query(string command){
    return influxdb.query(new query(command, database));
  }
 
  /**
   * 插入
   * @param tags 標(biāo)簽
   * @param fields 字段
   */
  public void insert(map<string, string> tags, map<string, object> fields){
    builder builder = point.measurement(measurement);
    builder.tag(tags);
    builder.fields(fields);
 
    influxdb.write(database, "", builder.build());
  }
 
  /**
   * 刪除
   * @param command 刪除語(yǔ)句
   * @return 返回錯(cuò)誤信息
   */
  public string deletemeasurementdata(string command){
    queryresult result = influxdb.query(new query(command, database));
    return result.geterror();
  }
 
  /**
   * 創(chuàng)建數(shù)據(jù)庫(kù)
   * @param dbname
   */
  public void createdb(string dbname){
    influxdb.createdatabase(dbname);
  }
 
  /**
   * 刪除數(shù)據(jù)庫(kù)
   * @param dbname
   */
  public void deletedb(string dbname){
    influxdb.deletedatabase(dbname);
  }
 
  public string getusername() {
    return username;
  }
 
  public void setusername(string username) {
    this.username = username;
  }
 
  public string getpassword() {
    return password;
  }
 
  public void setpassword(string password) {
    this.password = password;
  }
 
  public string getopenurl() {
    return openurl;
  }
 
  public void setopenurl(string openurl) {
    this.openurl = openurl;
  }
 
  public void setdatabase(string database) {
    this.database = database;
  }
}

3.存值

?
1
2
3
4
5
6
7
8
9
10
11
12
13
public class quatyserviceimpl{
private influxdbutil influxdb;
 
public void intodb() {
  influxdb = influxdbutil.setup();
  map<string, string> tags = new hashmap<>();
  map<string, object> fields = new hashmap<>();
  tags.put("tag_name",info.getkey());
  fields.put("tag_value",code);
  fields.put("timampest", df.format(new date()));
  influxdb.insert(tags, fields);
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/qq_36004521/article/details/80101608

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 黄色网在线播放 | www国产成人免费观看视频 | 色淫网站免费视频 | 亚洲国产成人久久一区www妖精 | 国产va在线观看 | 国产一级小视频 | 特大黑人videos与另类娇小 | 成人黄色免费视频 | 一级黄色性感片 | 日本中文一级片 | 午夜视频在线免费 | 精品成人国产在线观看男人呻吟 | 中文字幕在线观看免费 | 天堂二区 | 日韩av电影在线免费观看 | 高清视频91 | 午夜视频中文字幕 | 欧产日产国产精品乱噜噜 | 国产亚洲精品久久久久久久 | 成人福利免费在线观看 | 国产亚洲自拍一区 | 中文字幕电影免费播放 | 黄网站在线观 | 国产免费人做人爱午夜视频 | 亚洲性生活视频 | hd日本xxxx | 四季久久免费一区二区三区四区 | 国产成人精品一区二区仙踪林 | 欧美成人激情 | 国产91久久精品 | 视频一区二区视频 | 91久久线看在观草草青青 | 久久精品视频一区二区三区 | 久久视频精品 | 操操操操网 | 欧美 日韩 国产 在线 | 久久最新免费视频 | 凹凸成人精品亚洲精品密奴 | 亚洲国产美女视频 | 成人在线观看免费高清 | 另类亚洲孕妇分娩网址 |