Home » Wiki » How to Create SSL Connection to Amazon RDS for Db2 in Java Without KeyStore or Keytool

How to Create SSL Connection to Amazon RDS for Db2 in Java Without KeyStore or Keytool

by | Last updated Oct 12, 2025 | SSL Certificate

Create SSL Connection to Amazon RDS for Db2 in Java Without KeyStore or Keytool

You’re staring at another javax.net.ssl.SSLHandshakeException error. Your Java application needs to connect to Amazon RDS for Db2 over SSL, and every guide tells you to fire up keytool, create a KeyStore, import certificates, and manage trust stores. There has to be a simpler way, right?

Here’s the problem: traditional SSL setup in Java is a nightmare. You’re juggling keytool commands nobody remembers, converting PEM certificates to JKS format, and hoping your KeyStore password doesn’t break in production. But there’s a cleaner approach that skips all of this. This guide shows you how to create an SSL connection to Amazon RDS for Db2 in Java using the IBM JDBC driver’s sslCertLocation property – no KeyStore, no keytool, just straightforward code. Let’s break it down step by step.

Why Should You Skip KeyStore for RDS Db2 SSL Connections?

If you’ve ever set up SSL in Java, you know the drill. First, you download certificates. Then you convert them with OpenSSL. Next, you import them into a KeyStore using keytool. Finally, you point your application to that KeyStore with system properties or configuration files.

It works. But it’s painful.

Here’s what makes KeyStore management frustrating:

  • Complex setup: Five different commands just to import one certificate
  • Brittle automation: CI/CD pipelines break when KeyStore paths change
  • Format conversions: PEM to DER to JKS – why?
  • Password management: Another secret to rotate and secure

The sslCertLocation Advantage

The IBM Db2 JDBC driver supports a simpler approach. Instead of a KeyStore, you can point directly to a PEM certificate file using the sslCertLocation connection property. That’s it. No conversion. No imports. Just a path to your certificate bundle.

This method shines when you’re:

  • Building containerized applications (Docker, Kubernetes)
  • Running serverless functions (AWS Lambda)
  • Setting up CI/CD pipelines that need quick SSL testing
  • Prototyping without infrastructure overhead

Still use KeyStore if:

  • Your security policy requires centralized certificate management
  • You’re working with multiple databases requiring different certificates
  • Corporate compliance mandates Java trust store usage

What Do You Need to Connect to Amazon RDS Db2 with SSL?

Before you write any code, make sure you have these components ready.

1. Java Development Kit (JDK)

You’ll need JDK 8 or higher. Check your version:

java -version

The IBM JDBC driver works with JDK 8, 11, and 17. If you’re on Java 17, be aware of module system changes that might require additional –add-opens flags.

2. IBM Db2 JDBC Driver (db2jcc4.jar)

Download the IBM Data Server Driver for JDBC and SQLJ. The key file you need is db2jcc4.jar, typically located at ~/sqllib/java/db2jcc4.jar after installation.

You can also grab it from Maven Central:

<dependency>
  <groupId>com.ibm.db2</groupId> 
  <artifactId>jcc</artifactId> 
  <version>11.5.8.0</version> 
</dependency>

3. AWS RDS Certificate Bundle

Download the region-specific certificate bundle from AWS:

curl -sL https://truststore.pki.rds.amazonaws.com/us-east-1/us-east-1-bundle.pem -o us-east-1-bundle.pem

Important: Use region-specific bundles (like us-east-1-bundle.pem), not the global bundle. The JDBC driver has a known limitation with global-bundle.pem that causes connection failures.

4. RDS for Db2 Instance Configuration

Your RDS instance must have SSL enabled. After enabling SSL in the parameter group, restart your RDS instance. SSL changes don’t take effect without a restart – this trips up everyone the first time.

How to Create SSL Connection to RDS Db2 Without KeyStore (Step-by-Step)

Here’s the complete working example. I’ll explain each part.

Step 1: Set Up Your Connection Properties

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Db2SSLConnection {
    public static void main(String[] args) {
        // Configuration
        String certPath = "/path/to/us-east-1-bundle.pem";
        String host = "your-db-instance.abcdefg.us-east-1.rds.amazonaws.com";
        String port = "50001"; // Your SSL port
        String database = "TESTDB";
        String user = "admin";
        String password = "YourPassword";
        
        // Build JDBC URL with SSL properties
        String jdbcUrl = String.format(
            "jdbc:db2://%s:%s/%s:sslConnection=true;sslCertLocation=%s;",
            host, port, database, certPath
        );
        
        try {
            Connection conn = DriverManager.getConnection(jdbcUrl, user, password);
            System.out.println("SSL Connection successful!");
            
            // Test query
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY1");
            if (rs.next()) {
                System.out.println("Current timestamp: " + rs.getString(1));
            }
            
            rs.close();
            stmt.close();
            conn.close();
            
        } catch (Exception e) {
            System.err.println("Connection failed: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

Step 2: Understanding the Magic Properties

Two properties make this work:

sslConnection=true - Tells the driver to use SSL/TLS encryption 
sslCertLocation=/path/to/cert.pem - Points to your PEM certificate file

The driver reads the certificate, validates the server’s identity during the TLS handshake, and establishes an encrypted connection. No KeyStore involved.

Step 3: Compile and Run

javac -cp .:~/sqllib/java/db2jcc4.jar Db2SSLConnection.java
java -cp .:~/sqllib/java/db2jcc4.jar Db2SSLConnection
If everything works, you’ll see:
SSL Connection successful!
Current timestamp: 2025-01-15 14:23:45.123456

RDS Db2 SSL Connection Errors: Troubleshooting Guide

Error 1: “unable to find valid certification path to requested target”

Cause: The certificate path is wrong, or the certificate doesn’t match your RDS region.

Fix:

  • Verify the certificate file exists at the specified path
  • Ensure you’re using the region-specific bundle (not global-bundle.pem)
  • Check file permissions (the Java process needs read access)

Error 2: “Remote host terminated the handshake”

Cause: Your RDS instance doesn’t have SSL enabled, or it wasn’t restarted after enabling SSL.

Fix:

  • Check your RDS parameter group for rds.force_ssl=1
  • Restart the RDS instance (SSL changes require restart)
  • Verify the SSL port (usually different from the standard port)

Error 3: Works Locally, Fails in Docker/Lambda

Cause: The certificate path is hardcoded to a location that doesn’t exist in your container.

Fix for Docker:

COPY us-east-1-bundle.pem /app/certs/
ENV SSL_CERT_PATH=/app/certs/us-east-1-bundle.pem

Fix for Lambda: Include the certificate in your deployment package or download it to /tmp/ at runtime.

Debug Mode: See What’s Happening

Add this JVM argument to see detailed SSL handshake information:

java -Djavax.net.debug=ssl:handshake -cp ... Db2SSLConnection

How to Configure SSL Connection in Spring Boot with RDS Db2

If you’re using Spring Boot, configure your application.properties:

spring.datasource.url=jdbc:db2://your-host:50001/TESTDB:sslConnection=true;sslCertLocation=/app/certs/us-east-1-bundle.pem;
spring.datasource.username=admin
spring.datasource.password=${DB_PASSWORD}
spring.datasource.driver-class-name=com.ibm.db2.jcc.DB2Driver
Use environment variables for sensitive data like passwords and certificate paths. This keeps your configuration portable across environments.

RDS Db2 SSL Best Practices for Production Environments

1. Certificate Path Management

Use environment variables, not hardcoded paths:

String certPath = System.getenv("DB2_SSL_CERT_PATH");

2. Connection Pooling

SSL handshakes are expensive. Use connection pooling (HikariCP):

HikariConfig config = new HikariConfig();
config.setJdbcUrl(jdbcUrl);
config.setMaximumPoolSize(10);
config.setConnectionTimeout(30000);

3. Certificate Rotation

AWS rotates RDS certificates periodically. Automate certificate downloads in your deployment pipeline:

#!/bin/bash
curl -sL https://truststore.pki.rds.amazonaws.com/us-east-1/us-east-1-bundle.pem -o /app/certs/us-east-1-bundle.pem

4. Monitor SSL Connection Health

Log connection establishment times. SSL handshakes add 100-200ms overhead on first connect. If you see degradation, check certificate validity and network latency.

Final Verdict: KeyStore-Free Is the Way

Skipping KeyStore for Amazon RDS Db2 SSL connections isn’t just simpler – it’s more maintainable. You avoid certificate format conversions, eliminate keytool headaches, and make your deployment pipeline cleaner. For containerized applications, serverless functions, and rapid development, this approach wins every time.

Ready to simplify your SSL setup? Download the region-specific certificate bundle, add two properties to your JDBC URL, and you’re done. Your database connections will be encrypted, your deployment will be cleaner, and you’ll never have to remember another keytool command.

FAQs: Amazon RDS Db2 SSL Connection

Can I connect to Amazon RDS for Db2 without SSL?

Amazon RDS for Db2 allows non-SSL connections. Users must modify the security group rules to permit database access. The default configuration requires SSL connections for enhanced security.

How do I enable SSL for Amazon RDS Db2?

SSL is enabled by default on Amazon RDS for Db2 instances. The SSL certificate is automatically managed by AWS. Users need to configure their applications to use SSL parameters during connection setup.

What is the default port for Amazon RDS Db2?

The default port for Amazon RDS Db2 is 50000. Users can specify a different port during instance creation. The port number must be included in the JDBC connection string.

How do I connect to RDS Db2 using JDBC?

Users connect to RDS Db2 with a JDBC URL containing the endpoint, port, and database name. The connection requires valid credentials and SSL parameters. The driver class name is com.ibm.db2.jcc.DB2Driver.

How do I verify SSL connection to RDS Db2?

Users can verify SSL connections by checking the connection properties in their application logs. The database system tables show active connections with SSL status. The connection metadata contains SSL encryption details.

Why does SSL connection to RDS Db2 fail?

SSL connections fail due to incorrect certificate configuration. Network security groups may block required ports. Invalid SSL parameters in connection strings cause authentication errors.

What JDBC driver should I use for RDS Db2?

IBM Data Server Driver for JDBC works with RDS Db2. The driver version must be compatible with the database version. Users download the driver from IBM’s website or include it as a Maven dependency.

Priya Mervana

Priya Mervana

Verified Badge Verified Web Security Experts

Priya Mervana is working at SSLInsights.com as a web security expert with over 10 years of experience writing about encryption, SSL certificates, and online privacy. She aims to make complex security topics easily understandable for everyday internet users.

Stay Secure with SSLInsights!

Subscribe to get the latest insights on SSL security, website protection tips, and exclusive updates.

✅ Expert SSL guides
✅ Security alerts & updates
✅ Exclusive offers