c3p0 icon indicating copy to clipboard operation
c3p0 copied to clipboard

Connectivity Issue with SSL Truststore

Open gyvk opened this issue 6 years ago • 1 comments

Hello- I am trying to connect to Oracle DB using Spring c3p0 java. Without TLS properties, am able to connect successfully. AWS RDS Oracle DB has TLS enabled on different port, When i connect using TLS port from Spring with SSL Truststore properties added, am getting error.. I developed simple java code using jdbc & tried adding SSL truststore properties & able to connect..

Could you please advise on this whether the SSL properties will work with c3p0 ??

Error: "org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

Code:

ComboPooledDataSource dataSource = new ComboPooledDataSource(false);
            dataSource.setDataSourceName(name);
            dataSource.setIdentityToken(tokenname);
            dataSource.setDriverClass(driverClass);
            dataSource.setJdbcUrl(jdbcUrl);
            dataSource.setUser(user);
            dataSource.setPassword(password);
            dataSource.setInitialPoolSize(initialPoolSize);
            dataSource.setMinPoolSize(initialPoolSize);
            dataSource.setMaxPoolSize(maxPoolSize);

              Properties props = new Properties();
           props.setProperty("javax.net.ssl.trustStore", "/var/certs/test.jks");
           props.setProperty("javax.net.ssl.trustStoreType", "JKS");
           props.setProperty("javax.net.ssl.trustStorePassword", "****"); // Masked
               // Set the properties to datasource


            if (maxIdleTime > 0)
                dataSource.setMaxIdleTime(maxIdleTime);
            if (idleConnectionTestPeriod > 0)
                dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
            if (preferredTestQuery != null)
                dataSource.setPreferredTestQuery(preferredTestQuery);
            if (connectionCustomizerClassName != null)
                dataSource.setConnectionCustomizerClassName(connectionCustomizerClassName);
            if (checkoutTimeout != null)
                dataSource.setCheckoutTimeout((int) checkoutTimeout.toMillis());
            C3P0Registry.reregister(dataSource); 

gyvk avatar Jan 30 '19 19:01 gyvk

I had a similar problem. This is old, but it could help.

In this case: You are not setting the properties to the dataSource.

You can do it with: dataSource.setProperties(props);

But do it before setting any other properties otherwise it will flush them.

So something like that: ComboPooledDataSource dataSource = new ComboPooledDataSource(false); Properties props = new Properties(); props.setProperty("javax.net.ssl.trustStore", "/var/certs/test.jks"); props.setProperty("javax.net.ssl.trustStoreType", "JKS"); props.setProperty("javax.net.ssl.trustStorePassword", "****"); // Masked dataSource.setProperties(props); dataSource.setDataSourceName(name); ...

lavoiekeven avatar Sep 27 '21 15:09 lavoiekeven