Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connectivity Issue with SSL Truststore #125

Open
gyvk opened this issue Jan 30, 2019 · 1 comment
Open

Connectivity Issue with SSL Truststore #125

gyvk opened this issue Jan 30, 2019 · 1 comment

Comments

@gyvk
Copy link

gyvk commented Jan 30, 2019

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); 

@lavoiekeven
Copy link

lavoiekeven commented Sep 27, 2021

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);
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants