简体   繁体   中英

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".

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

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. Still getting unauthorized exception:
Failed to create database mydb; Unauthorized

You have to set the user and password (default user "root", password empty):

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). Which comes with a new API and a better performance). 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM