Skip to content

Using JDBC Driver

Enrico Olivelli edited this page Sep 3, 2020 · 3 revisions

HerdDB JDBC Drivers

HerdDB comes with JDBC Drivers, that allow to connect to a standalone server, an HerdDB cluster or even to start an in-memory only server.

JDBC Drivers dependency

Add a dependency to the JDBC Driver using your favourite dependency management system

Search on Maven central for latest and greatest version

Alternatively use the FAT/Uber JDBC Jar provided inside the release package (you could find it also on Maven) using classifiers 'uber' and 'thin'. The 'thin' driver is not able to start an Embedded Server in cluster mode, it is useful only to connect to remote servers or to run local unit tests (run in 'local' mode), basically because it lacks BookKeeper dependencies.

In memory server for tests

In order to start an embedded server for unit tests just use the following configuration:

  • JDBC URL: jdbc:herddb:local:dbname (you can have multiple datasources on the same JVM, just change 'dbname')
  • JDBC Driver classname: herddb.jdbc.Driver
  • Username: sa
  • Password: hdb

In memory server but with persistent data

In order to start an embedded server and persist data just use the following configuration:

  • JDBC URL: jdbc:herddb:localhost:7000?server.start=true&server.data.dir=PATH_TO_DIRECTORY
  • JDBC Driver classname: herddb.jdbc.Driver
  • Username: sa
  • Password: hdb This is one of the suggested ways to run HerdDB in a non distributed application, ensure that PATH_TO_DIRECTORY is an absolute directory or that the process is running on a known directory.

Standalone server

In order to connect to an existing server use the following configuration:

  • JDBC URL: jdbc:herddb:servername:port (default server/port is jdbc:herddb:localhost:7000)
  • JDBC Driver classname: herddb.jdbc.Driver
  • Username: sa
  • Password: hdb

Cluster

In order to connect to an existing cluster use the following configuration:

  • JDBC URL: jdbc:herddb:zookeeper:zkConnectionString/herddb (default is jdbc:herddb:zookeeper:localhost:2181/herddb)
  • JDBC Driver classname: herddb.jdbc.Driver
  • Username: sa
  • Password: hdb

When you are using a production system you will have multiple zookeeper servers, then you have to separate the items with a comma, like jdbc:herddb:zookeeper:server1:2181,server2:2181/herddb

Authentication

You can use username/password authentication as JDBC allows, but secured environments are expected to use Kerberos/GSSAPI using JAAS. In order to use JAAS you have to configure -Djava.security.krb5.conf and -Djava.security.auth.login.config in your application.

This is an example of JAAS configuration file that declares the HerdDBClient section: https://github.com/diennea/herddb/blob/master/herddb-core/src/test/java/herddb/server/security/JAASKerberosTest.java#L99

Clone this wiki locally