[英]Getting “Unauthorized” exception when trying to create connection in Arango database using Java
我正在尝试使用Java,IDE-Eclipse在Arango数据库中创建连接,但是在执行该程序时,出现了“未经授权”异常。
注意:我已经使用用户: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());
}
}
}
我使用了教程https://www.arangodb.com/tutorials/tutorial-java-old/来编写此程序,并遵循了所有提到的步骤。 仍然会出现未经授权的异常:
Failed to create database mydb; Unauthorized
您必须设置用户和密码(默认用户“ root”,密码为空):
ArangoConfigure configure = new ArangoConfigure();
configure.init();
configure.setUser("root");
configure.setPassword("");
ArangoDriver arangoDriver = new ArangoDriver(configure);
另外,我强烈建议您更新到新的Java驱动程序(版本4.1.12)。 其中带有新的API和更好的性能)。 也有一个教程(请参阅此处 )。
在此版本中,您的问题所需的代码为:
ArangoDB arangoDB = ArangoDB.Builder().user("root").password("").build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.