65

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?

user962206
  • 15,637
  • 61
  • 177
  • 270
  • 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 –  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

9 Answers9

93

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
  • 26,212
  • 21
  • 100
  • 111
24

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,987
  • 1
  • 15
  • 21
  • 8
    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
  • First make sure you have imported the driver in pom.xml (in case you're using maven), then proceed to read the answers – testing_22 Apr 22 '22 at 17:59
11

The issue I had was that I had given double quotes for the datasource url in the properties file.

What I had given :

spring.datasource.url="jdbc:postgresql://localhost:5432/postgres"

The correct way to give the url is :

spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
Jyotirmay Dash
  • 129
  • 1
  • 3
2

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

breadman0
  • 163
  • 1
  • 4
  • 14
2

I was having the same error until I realize that I did not set my profile to active in the application.properties class.

spring.profiles.active = dev
Procrastinator
  • 2,526
  • 30
  • 27
  • 36
Salami Korede
  • 339
  • 2
  • 9
2

Replace

postgresql://localhost/db_name

with

jdbc:postgresql://localhost/db_name
Akash Verma
  • 638
  • 1
  • 11
  • 15
1

I had the same issue with h2 DB in WebFlux. The issue was with spring.datasource.driver

Not working

spring.datasource.driver=org.h2.Driver

Working

spring.datasource.driver-class-name=org.h2.Driver
jfk
  • 4,335
  • 34
  • 27
1

I had the same error. I had previously used the following in my application.properties. I had prefixed the database url with jdbc:postgres

    >JDBC_DATABASE_URL=jdbc:postgres://host.com:5432/dbName

We need to use postgresql instead of postgres.

    >JDBC_DATABASE_URL=jdbc:postgresql://host.com:5432/dbName
benitta.ruphus
  • 106
  • 1
  • 6
0

In my case, two configuration files are in different format:

  1. application.properties in src/main/resources
  2. application.yml in src/test/resources

After changing application.yml to application.properties in src/test/resources, the issue was fixed.