Ready to get started?

Learn more about the CData JDBC Driver for Wasabi or download a free trial:

Download Now

Create a Data Access Object for Wasabi Data using JDBI

A brief overview of creating a SQL Object API for Wasabi data in JDBI.

JDBI is a SQL convenience library for Java that exposes two different style APIs, a fluent style and a SQL object style. The CData JDBC Driver for Wasabi integrates connectivity to live Wasabi data in Java applications. By pairing these technologies, you gain simple, programmatic access to Wasabi data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read Wasabi data.

Create a DAO for the Wasabi Buckets Entity

The interface below declares the desired behavior for the SQL object to create a single method for each SQL statement to be implemented.

public interface MyBucketsDAO { //request specific data from Wasabi (String type is used for simplicity) @SqlQuery("SELECT OwnerId FROM Buckets WHERE Name = :name") String findOwnerIdByName(@Bind("name") String name); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Wasabi

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Wasabi.

To authorize Wasabi requests, provide the credentials for an administrator account or for an IAM user with custom permissions. Set AccessKey to the access key Id. Set SecretKey to the secret access key.

Note: You can connect as the AWS account administrator, but it is recommended to use IAM user credentials to access AWS services.

For information on obtaining the credentials and other authentication methods, refer to the Getting Started section of the Help documentation.

Built-in Connection String Designer

For assistance in constructing the JDBC URL, use the connection string designer built into the Wasabi JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.wasabi.jar

Fill in the connection properties and copy the connection string to the clipboard.

A connection string for Wasabi will typically look like the following:

jdbc:wasabi:AccessKey=a123;SecretKey=s123;

Use the configured JDBC URL to obtain an instance of the DAO interface. The particular method shown below will open a handle bound to the instance, so the instance needs to be closed explicitly to release the handle and the bound JDBC connection.

DBI dbi = new DBI("jdbc:wasabi:AccessKey=a123;SecretKey=s123;"); MyBucketsDAO dao = dbi.open(MyBucketsDAO.class); //do stuff with the DAO dao.close();

Read Wasabi Data

With the connection open to Wasabi, simply call the previously defined method to retrieve data from the Buckets entity in Wasabi.

//disply the result of our 'find' method String ownerId = dao.findOwnerIdByName("TestBucket"); System.out.println(ownerId);

Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Wasabi by integrating with the CData JDBC Driver for Wasabi. Download a free trial and work with live Wasabi data in custom Java applications today.