I\'m trying to create a datasource from my Heroku/Spring application to postgres.heroku.com postgres database. Here is my applicationContext.xml
snippet.
Following worked for me:
jdbc:postgresql://url/databaseName?sslmode=require&sslfactory=org.postgresql.ssl.NonValidatingFactory
I'd to change ssl=true
to sslmode=require
You need to extend your JDBC connection URL with the relevant ssl information.
Your JDBC connection URL will need to include the following:
ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
So in your case the URL would be:
jdbc:postgresql://url/dstabase?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
Source for this info: https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#connecting-to-a-database-remotely
When connecting to Heroku Postgres with jdbc, you will also sometimes get an error unless you add the SSL parameters to the url:
ssl=true
sslfactory=org.postgresql.ssl.NonValidatingFactory
It worked for me:
<bean id="securityDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://host:port/database?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"/>
<property name="username" value="user"/>
<property name="password" value="password"/>
</bean>
The mistake I was doing was using an & instead of &
(silly I know)
?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
and yes the link definitely is helpful: https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#connecting-to-a-database-remotely
AND Keep in mind: in this link, jdbc:postgres://host.. is used, which might not be suitable for you (use postgresql instead) if No suitable Sql driver error occurs