JDBC Driver

Installing the JDBC Driver Jar

If you are using Maven, for your code to be able to reference the jdbc driver you will need to install the jar in your local maven repository. In your project's main directory, issue the following command:

mvn install:install-file -Dfile=<path>/sonicbase-jdbc-<version>.jar -DgroupId=com.sonicbase -DartifactId=sonicbase-jdbc -Dversion=<version> -Dpackaging=jar

For example:

mvn install:install-file -Dfile=/home/user/sonicbase-jdbc-0.9.2.jar -DgroupId=com.sonicbase -DartifactId=sonicbase-jdbc -Dversion=0.9.2 -Dpackaging=jar

The jar is located in the "lib" directory of the install directory. It is named "sonicbase-<version>.jar".

Then add the jar to your project pom.xml file. In the dependencies section add the following:



JDK Requirements

The jvm running the jdbc driver needs to be at least version 8.


Include the following line before creating a connection:

Connect to the database with the following code:
    Connection conn = DriverManager.getConnection("jdbc:sonicbase:<address-0>:<port-0>,<address-1>:<port-1><address-n>:<port-n>/<database name>");

"address-0" thru "address-n" should be the ip addresses of all the replicas of shard 0. Enter all the replicas of the first shard configured in the config file for this cluster. Note that each address/port combination is separated by a comma. For the free version, only one replica may be specified.

Connection Pool

C3P0 is a good connection pool to use. Below is an example of how to use it:

ComboPooledDataSource cpds = new ComboPooledDataSource();

cpds.setMinPoolSize(5); cpds.setAcquireIncrement(1); cpds.setMaxPoolSize(20);
//aquire connection Connection conn = cpds.getConnection();
//release connection conn.close();