43

I've pushed my application to cloudfoundry. However every time I connect to my postgresql/elephant sql I received this error

 Driver org.postgresql.Driver claims to not accept JDBC URL jdbc:postgres://cwkqmdql:SsVqwdLxQObgaJAYu68O-8gTY1VmS9LX@pellefant.db.elephantsql.com:5432/cwkqmdql/

Is there anything I've missed?

a_horse_with_no_name
  • 440,273
  • 77
  • 685
  • 758
user962206
  • 13,699
  • 56
  • 164
  • 259
  • The URL is indeed invalid. If the part `cwkqmdql:SsVqwdLxQObgaJAYu68O-8gTY1VmS9LX` is supposed to be username and password, then you can't specify it like that. See the manual for the correct URL: https://jdbc.postgresql.org/documentation/94/connect.html – a_horse_with_no_name Jan 12 '16 at 11:26
  • @a_horse_with_no_name I tried changing my spring.datasource.url to this jdbc:postgres://pellefant-01.db.elephantsql.com:5432/cwkqmdql and the same error still persists – user962206 Jan 12 '16 at 23:17

3 Answers3

63

There are a few issues with that URL and a latest PSQL driver may complain.

  1. jdbc:postgres: should be replaced with jdbc:postgresql:
  2. Do not use jdbc:postgresql://<username>:<passwor>..., user parameters instead: jdbc:postgresql://<host>:<port>/<dbname>?user=<username>&password=<password>
  3. In some cases you have to force SSL connection by adding sslmode=require parameter

So your URL should be:

jdbc:postgresql://@pellefant.db.elephantsql.com:5432/cwkqmdql?user=cwkqmdql&password=SsVqwdLxQObgaJAYu68O-8gTY1VmS9LX

or

jdbc:postgresql://@pellefant.db.elephantsql.com:5432/cwkqmdql?user=cwkqmdql&password=SsVqwdLxQObgaJAYu68O-8gTY1VmS9LX&sslmode=require

I hope that will help.

Tom
  • 24,084
  • 18
  • 92
  • 104
15

In my case it was defining the property in double quotes in the java.properties file

by changing

jdbcUrl="url"

to

jdbcUrl=url

it works again

Thami Bouchnafa
  • 1,449
  • 1
  • 12
  • 18
  • 6
    ooops, that was my issue, too. Thank you – rob Nov 13 '18 at 08:16
  • 1
    This was the issue too. For my case, the confusion comes from different syntax for different config files (application.properties vs application.yml) – Hoàng Long Dec 14 '18 at 08:04
  • what if i am using helm chart to create secret and while creating secrets we need to surround each value with quotes.. then in applications.properties, we inject the env var. – Abdennour TOUMI Feb 21 '21 at 11:19
1

also had this error, but realized it was because i had typed postgressql instead of postgresql in my url

breadman0
  • 123
  • 8