1
votes

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

1

1 Answers

2
votes

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();