Trying to connect InfluxDB through Java. Please check below the following code :
public InfluxConnect() {
this.influxDB = InfluxDBFactory.connect("http://localhost:8086", "avinflux", "Stallions@7891");
this.influxDB.setLogLevel(InfluxDB.LogLevel.BASIC);
Pong response = this.influxDB.ping();
if (response.getVersion().equalsIgnoreCase("unknown")) {
System.out.println("unknown");
}
else System.out.println("response is : "+response.toString());
try {
@SuppressWarnings("deprecation")
String databaseName = "NOAA_water_database";
this.influxDB.query(new Query("CREATE DATABASE " + databaseName));
this.influxDB.setDatabase(databaseName);
}
catch(Exception e)
{
System.out.println("In Catch");
e.printStackTrace();
}
}
**Error which i am getting **
Jul 27, 2021 3:40:57 PM okhttp3.internal.platform.Platform log
INFO: <-- 401 Unauthorized http://192.168.105.191:8086/query?q=CREATE+DATABASE+NOAA_water_database (0ms, 48-byte body)
In Catch
org.influxdb.InfluxDBException: {"code":"unauthorized","message":"Unauthorized"}
at org.influxdb.InfluxDBException.buildExceptionForErrorState(InfluxDBException.java:175)
Same credential when i am using after hitting http://localhost:8086/ on web browser and it is working fine but when i am trying to connect through java code it is not working and throwing above exception
Not able to find where exactly is the problem.
Can anybody please suggest/find out the problem?