Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to create a datasource from my Heroku/Spring application to postgres.heroku.com postgres database. Here is my applicationContext.xml snippet.

<bean id="securityDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://url/dstabase"/>
    <property name="username" value="user"/>
    <property name="password" value="password"/>
</bean>

But when I run the app, tomcat gives this error:

Cannot create PoolableConnectionFactory (FATAL: no pg_hba.conf entry for host "10.11.12.13", user "username", database "database", SSL off)

How can I configure it to use SSL? I need it in order to stablish a connection against postgres.heroku.com

share|improve this question
    
Got to admit I've never used PostgreSQL or Heroku but am guessing the following should help: devcenter.heroku.com/articles/… –  DB5 Aug 6 '12 at 18:55
    
@DB5 that sounds correct, you should put it as an answer –  araqnid Aug 6 '12 at 21:16
    
how did you resolve this? –  Palak Darji Mar 27 '14 at 13:37

4 Answers 4

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&amp;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

share|improve this answer

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
share|improve this answer

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&amp;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 &amp; (silly I know)

 ?ssl=true&amp;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

share|improve this answer

Most likely, you just need to allow remote connections for your db. Check this link: How to configure PostgreSQL to accept all incoming connections

share|improve this answer
    
The linked answer doesn't apply to Heroku's Postgres databases as it is impossible to access the config files. –  Andre Nov 24 '14 at 18:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.