Connecting JDBC applications with SSL
You can configure database connections for the HCL OneDB™ JDBC Driver to use the Secure Sockets Layer (SSL) protocol.
Before you begin
Procedure
JDBC sample for SSL connection
This sample Java program highlights the operations that are required to connect to the stores_demo database by using SSL.
import java.sql.Connection; import java.sql.SQLException; import com.onedb.jdbcx.OneDBDataSource; public class SSLConnectionExample { public static void main(String[] args) { /* System properties for keystore */ /* you can set this here for your whole system or you can set on */ /* the data source (show below) or directly on your connection */ /* properties using SSL_TRUSTSTORE and SSL_TRUSTSTORE_PASSWORD */ System.setProperty("javax.net.ssl.trustStore", "/path/to/keystore"); System.setProperty("javax.net.ssl.trustStorePassword", "password"); /* Instantiate OneDB data source */ OneDBDataSource ds = new OneDBDataSource(); ds.setUser("dbuser"); ds.setPassword("password"); ds.setDatabase("stores_demo"); ds.setPort(9888); /* Enable SSL/TLS (required when using SSL/TLS) */ cds.setEncrypt(true); /* Optional if you don't set a system property */ /* You can set the trust store and password in the data source */ cds.setTrustStore("/opt/keystore"); cds.setTrustStorePassword("password"); try (Connection conn = ds.getConnection()) { System.out.println(" Successfully connected to database using SSL Connection"); System.out.println(" Database version ...: " + conn.getMetaData().getDatabaseProductVersion()); } catch (SQLException e) { System.err.println("Error Message : " + e.getMessage()); System.err.println("Error Code : " + e.getErrorCode()); } } }