Skip to content

Commit 9bd8c84

Browse files
committed
Added PR #600 information to README.
1 parent 1ff6638 commit 9bd8c84

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,48 @@ try (InfluxDB influxDB = InfluxDBFactory.connect("http://172.17.0.2:8086", "root
160160
}
161161
```
162162

163+
#### Default database to query
164+
165+
If you only use one database you can set client level database information. This database will be used for all subsequent HTTP queries,
166+
but if you still sometimes need to query some different database you can, you need to provide provide database information directly in the query,
167+
then database information in the query will take precedence and query will be pushed to that database.
168+
This is shown in the following example:
169+
170+
```java
171+
// Database names
172+
InfluxDB influxDB = InfluxDBFactory.connect("http://172.17.0.2:8086", "root", "root");
173+
174+
String db1 = "database1";
175+
influxDB.query(new Query("CREATE DATABASE " + db1));
176+
String defaultRpName = "aRetentionPolicy1";
177+
influxDB.query(new Query("CREATE RETENTION POLICY " + rp1 + " ON " + db1 + " DURATION 30h REPLICATION 2 DEFAULT"));
178+
Point point1 = Point.measurement("cpu")
179+
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
180+
.addField("idle", 90L)
181+
.addField("user", 9L)
182+
.addField("system", 1L)
183+
.build();
184+
influxDB.write(db1, rp1, point1); // Write to db1
185+
186+
String db2 = "database2";
187+
influxDB.query(new Query("CREATE DATABASE " + db2));
188+
String rp2 = "aRetentionPolicy1";
189+
influxDB.query(new Query("CREATE RETENTION POLICY " + rp2 + " ON " + db2 + " DURATION 30h REPLICATION 2 DEFAULT"));
190+
Point point2 = Point.measurement("cpu")
191+
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
192+
.addField("idle", 80L)
193+
.addField("user", 8L)
194+
.addField("system", 2L)
195+
.build();
196+
influxDB.write(db2, rp2, point2); // Write to db2
197+
198+
199+
influxDB.query(new Query("SELECT * FROM cpu")); // Returns Point1
200+
influxDB.query(new Query("SELECT * FROM cpu", db2)) // Returns Point2
201+
202+
```
203+
204+
163205
### Advanced Usage
164206

165207
#### Gzip's support (version 2.5+ required)

0 commit comments

Comments
 (0)