[英]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.