Quick Start: Progress® DataDirect® for JDBC™ for Apache Cassandra™ Driver

The following information enables you to connect with and test your driver immediately after installation. For installation instructions, refer to the Progress DataDirect for JDBC Drivers Installation Guide. This Quick Start covers the following topics:

Connecting to a Database

Testing the Connection

Tuning the Driver for Optimal Performance

Connecting to a Database

Once the driver is installed, you can connect from your application to your data store in two ways: using the JDBC Driver Manager or using a JNDI data source. The following section provides information you need to get started using the driver with the Driver Manager. For information on using data sources, refer to the Progress DataDirect for JDBC for Apache Cassandra User's Guide.

Setting the Classpath

Set your system CLASSPATH to include the cassandra.jar file:

install_dir/lib/cassandra.jar
Windows Example
CLASSPATH=.;C:\Program Files\Progress\DataDirect\JDBC_60\lib\cassandra.jar
UNIX/Linux Example
CLASSPATH=.:/opt/Progress/DataDirect/JDBC_60/lib/cassandra.jar

Passing the Connection URL

Connect from an application to a database with the JDBC Driver Manager by specifying a connection URL in the DriverManager.getConnection() method.

A connection URL takes the form:

jdbc:datadirect:cassandra://server:port;KeyspaceName=keyspace;

[property=value[;...]]

where:

server specifies the name or the IP address of the server to which you want to connect.

port specifies the port of the server that is listening for connections to the Cassandra keyspace. The default is 9042.

keyspace specifies the default name of the Cassandra keyspace to which the driver connects. This value is used as the default qualifier for unqualified table names in SQL queries.

property=value specifies connection property settings. Multiple properties are separated by a semi-colon. (Refer to the User's Guide for connection property descriptions.)

Example

The following example shows how to establish a connection by specifying a connection URL and how to verify the connection by printing database metadata.

// Establish the Connection
String url = "jdbc:datadirect:cassandra://MyServer:9042;KeyspaceName=MyKS"
Connection con = DriverManager.getConnection(url, "admin", "adminpass");
// Verify the Connection
DatabaseMetaData metaData = con.getMetaData();
System.out.println("Database Name: " + metaData.getDatabaseProductName());
System.out.println("Database Version: " + 
metaData.getDatabaseProductVersion());

Testing the Connection

You can take the following steps to test your connection with DataDirect Test™ for JDBC.

1.      Start DataDirect Test by running testforjdbc.bat or testforjdbc.sh in the install_dir/testforjdbc directory, where install_dir is your installation directory.

2.      Click Press Here to Continue.

3.      From the Connection menu, select Connect to DB.

4.      Select the appropriate template for your data source and specify values for the appropriate connection properties. Specify your user name and password if required. Click OK.

5.      A new connection window opens if the connection information was entered correctly. If the connection cannot be established, an error is displayed in the JDBC/Database Output window.

Refer to the User's Guide for more information about using DataDirect Test for JDBC.

Tuning the Driver for Optimal Performance

The driver has connection properties that directly affect performance. For a Driver Manager connection, a property is expressed as a key value pair and takes the form property=value. To tune the driver for optimal performance, consider setting the following connection properties. (Refer to the User's Guide for details on these and other connection properties.)

If you know the typical fetch size for your application

Set FetchSize to suit your environment. Smaller fetch sizes can improve the initial response time of the query. Larger fetch sizes improve overall fetch times at the cost of additional memory.

If your application handles insensitive result set data

Increase InsensitiveResultSetBufferSize. By increasing the value of this property, you increase the amount of insensitive result set data the driver holds in memory and avoid writing the insensitive result set data to disk. The default is 2048 KB.

If your application retrieves large sets of data

Set ResultMemorySize to suit your requirements. This property specifies the maximum size (in MB) of an intermediate result set that the driver holds in memory. When this threshold is reached, the driver writes a portion of the result set to disk in temporary files. Increasing this value can improve performance by avoiding the need to page to disk. However, out-of-memory errors can occur when a result set exceeds the available heap size used by the JVM. Decreasing the value of ResultMemorySize reduces the risk of such out-of-memory errors.

By default, ResultMemorySize is a percentage of the max Java heap size. Therefore, as an alternative, you can increase max Java heap size to increase the maximum size of an intermediate result that the driver holds in memory. This can improve performance and reduce the likelihood of out-of-memory errors.

If your application uses statement pooling and the driver is not running from within an application server or from within another application that provides its own statement pooling

Set MaxPooledStatements to x where x is a positive integer that represents a number of pooled prepared statements.

© 2016. Progress Software Corporation. All rights reserved.