W3cubDocs

/RethinkDB Java

ReQL command: connection

Command syntax

r.connection() → builder

Description

Create a new connection to the database server. connection returns a builder object with the following methods:

  • hostname(): the host to connect to (default localhost).
  • port(): the port to connect on (default 28015).
  • dbname(): the default database (default test).
  • user(): the user account and password to connect as (default "admin", "").
  • timeout(): timeout period in seconds for the connection to be opened (default 20).
  • connect(): instantiate a connection object with the parameters previously passed to the builder.
  • certFile(): a path to an SSL CA certificate.
  • sslContext(): an instance of an SSLContext class to use for SSL connections.

Either certFile or sslContext must be supplied to make an SSL connection to the RethinkDB server. Only one should be used.

If the connection cannot be established, a ReqlDriverError will be thrown.

Using SSL with RethinkDB requires proxy software on the server, such as Nginx, HAProxy or an SSL tunnel. RethinkDB will encrypt traffic and verify the CA certification to prevent man-in-the-middle attacks. Consult your proxy’s documentation for more details.

Alternatively, you may use RethinkDB’s built-in TLS support.

Example: Open a connection using the default host and port, specifying the default database.

Connection conn = r.connection().connect();

Example: Open a new connection, specifying parameters.

Connection conn = r.connection()
    .hostname("localhost")
    .port(28015)
    .dbname("marvel")
    .connect();

Example: Open a new connection, specifying a user/password combination for authentication.

Connection conn = r.connection()
    .hostname("localhost")
    .port(28015)
    .dbname("marvel")
    .user("herofinder", "metropolis")
    .connect();

Example: Open a new connection to the database using an SSL proxy.

Connection conn = r.connection()
    .hostname("localhost")
    .port(28015)
    .dbname("marvel")
    .authKey("hunter2")
    .certFile("/path/to/ca.crt")
    .connect();

Related commands

Get more help

Couldn't find what you were looking for?

© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/java/connect/