[英]Getting “Unauthorized” exception when trying to create connection in Arango database using Java
I am trying to create a connection in Arango databse using Java , IDE- Eclipse but while executing the program I am getting the exception "Unauthorized". 我正在尝试使用Java,IDE-Eclipse在Arango数据库中创建连接,但是在执行该程序时,出现了“未经授权”异常。
Note: I have logged in to Arango Database with user :root URL- http://127.0.0.1:8529/_db/_system/_admin/aardvark/index.html#logs 注意:我已经使用用户:root URL- http://127.0.0.1:8529/_db/_system/_admin/aardvark/index.html#logs登录到Arango数据库。
Program in Eclipse
import static com.arangodb.*;
public class FirstProject {
public static void main(String[] args) {
ArangoConfigure configure = new ArangoConfigure();
configure.init();
ArangoDriver arangoDriver = new ArangoDriver(configure);
String dbName = "mydb";
try {
arangoDriver.createDatabase(dbName);
System.out.println("Database created: " + dbName);
} catch (Exception e) {
System.out.println("Failed to create database " + dbName + "; " + e.getMessage());
}
}
}
I have used the tutorial https://www.arangodb.com/tutorials/tutorial-java-old/ to write this program and followed all the steps mentioned. 我使用了教程https://www.arangodb.com/tutorials/tutorial-java-old/来编写此程序,并遵循了所有提到的步骤。 Still getting unauthorized exception: 仍然会出现未经授权的异常:
Failed to create database mydb; Unauthorized
You have to set the user and password (default user "root", password empty): 您必须设置用户和密码(默认用户“ root”,密码为空):
ArangoConfigure configure = new ArangoConfigure();
configure.init();
configure.setUser("root");
configure.setPassword("");
ArangoDriver arangoDriver = new ArangoDriver(configure);
In addition I highly suggest you to update to the new java driver (version 4.1.12). 另外,我强烈建议您更新到新的Java驱动程序(版本4.1.12)。 Which comes with a new API and a better performance). 其中带有新的API和更好的性能)。 There is also a tutorial for it (see here ). 也有一个教程(请参阅此处 )。
The required code for your problem in this version would be: 在此版本中,您的问题所需的代码为:
ArangoDB arangoDB = ArangoDB.Builder().user("root").password("").build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.