How to select a database with remote Gremlin Client

I have been using the following sample code to connect with OrientDB (3.0.31) server.

public ResultSet query(String query)
{
    Client client = getClient();
    return client.submit(query);
}

public Client getClient()
{
    return getCluster(getSettings()).connect().init();
}

public Cluster getCluster(Settings settings)
{
    Cluster.Builder builder = Cluster.build().
        addContactPoint(settings.getHostname()).
        port(settings.getPort()).
        serializer(settings.getSerializer()).
        credentials(settings.getUser(), settings.getPass());

    return builder.create()
}

It worked alright, but now I need to be able to select a specific database from OrientDB. You can do this with the OrientGraph:

OrientGraph g = OrientGraph.open("remote:localhost/myDatabase","user","pass");

But I have string queries in my program and not byte code. Is there a way to select the database “myDatabase” using the above code? Also is there a way to browse all the available database?

Hi @thanosG

by default the client uses the g binding, if you are using the TP3 edition by default the demodb is exposed as g.

If you want to host multiple graph you should bind them with different letters like g,g1,g2 etc and then use the alias from the client as explained here

https://tinkerpop.apache.org/docs/current/reference/#_aliases

For reference you can find the config here for the demodb

gremlin-server.yaml
demodb.properties
demodb.groovy

The latter script is responsible for creating the binding to g

You can find the docs on the gremlin server here

Let me know if this helps

Thanks @wolf4ood for you answer! I used your proposed way and it works.

The only problem remaining is when I create a new database I have to edit the yaml/groovy file and restart the server in order to be able to use the new database. Is there something I could do about that, or is this a limitation?