Installing the JDBC Driver JarIf 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-<version>.jar -DgroupId=com.sonicbase -DartifactId=sonicbase -Dversion=<version> -Dpackaging=jar
mvn install:install-file -Dfile=/home/user/sonicbase-0.9.2.jar -DgroupId=com.sonicbase -DartifactId=sonicbase -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:
<dependency> <groupId>com.sonicbase</groupId> <artifactId>sonicbase</artifactId> <version><version></version> </dependency>
JDK RequirementsThe jvm running the jdbc driver needs to be at least version 7.
ConnectingInclude 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 PoolC3P0 is a good connection pool to use. Below is an example of how to use it:
ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDriverClass("Driver"); cpds.setJdbcUrl("jdbc:sonicbase:localhost:9010/db");
cpds.setMinPoolSize(5); cpds.setAcquireIncrement(1); cpds.setMaxPoolSize(20);
//aquire connection Connection conn = cpds.getConnection();
//release connection conn.close();