Ready to get started?

Download a free trial of the Amazon DynamoDB Driver to get started:

 Download Now

Learn more:

Amazon DynamoDB Icon Amazon DynamoDB JDBC Driver

Connect Java applications with the DynamoDB real-time NoSQL cloud database service. Use Amazon DynamoDB as the big data backend that powers your Java/J2EE applications.

Connect to Amazon DynamoDB Data in JRuby

Create a simple JRuby app with access to live Amazon DynamoDB data.

JRuby is a high-performance, stable, fully threaded Java implementation of the Ruby programming language. The CData JDBC Driver for Amazon DynamoDB makes it easy to integrate connectivity to live Amazon DynamoDB data in JRuby. This article shows how to create a simple JRuby app that connects to Amazon DynamoDB data, executes a query, and displays the results.

Configure a JDBC Connection to Amazon DynamoDB Data

Before creating the app, note the installation location for the JAR file for the JDBC Driver (typically C:\Program Files\CData\CData JDBC Driver for Amazon DynamoDB\lib).

JRuby natively supports JDBC, so you can easily connect to Amazon DynamoDB and execute SQL queries. Initialize the JDBC connection with the getConnection function of the java.sql.DriverManager class.

The connection to Amazon DynamoDB is made using your AccessKey, SecretKey, and optionally your Domain and Region. Your AccessKey and SecretKey can be obtained on the security credentials page for your Amazon Web Services account. Your Region will be displayed in the upper left-hand corner when you are logged into DynamoDB.

Built-in Connection String Designer

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

java -jar cdata.jdbc.amazondynamodb.jar

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

Below is a typical JDBC connection string for Amazon DynamoDB:

jdbc:amazondynamodb:Access Key=xxx;Secret Key=xxx;;Region=OREGON;

Create a JRuby App with Connectivity to Amazon DynamoDB Data

Create a new Ruby file (for example: AmazonDynamoDBSelect.rb) and open it in a text editor. Copy the following code into your file:

require 'java' require 'rubygems' require 'C:/Program Files/CData/CData JDBC Driver for Amazon DynamoDB 2018/lib/cdata.jdbc.amazondynamodb.jar' url = "jdbc:amazondynamodb:Access Key=xxx;Secret Key=xxx;;Region=OREGON;" conn = java.sql.DriverManager.getConnection(url) stmt = conn.createStatement rs = stmt.executeQuery("SELECT Industry, Revenue FROM Lead") while ( do puts rs.getString(1) + ' ' + rs.getString(2) end

With the file completed, you are ready to display your Amazon DynamoDB data with JRuby. To do so, simply run your file from the command line:

jruby -S AmazonDynamoDBSelect.rb

Writing SQL-92 queries to Amazon DynamoDB allows you to quickly and easily incorporate Amazon DynamoDB data into your own JRuby applications. Download a free trial today!