0

I have Spring/Hibernate application that is using MySQL database. I deployed it on Heroku and converted my db properties file according Heroku Postgres settings, but after application starts I receive following error:

java.sql.SQLException: No suitable driver found for jdbc:postgresql://okhuoxugkgndyv:42a41d66da81c48b4242a408f6f5ab95a8b6af21eb2150fed2b8c6cf50ef27a7@ec2-54-246-87-132.eu-west-1.compute.amazonaws.com:5432/de0n3c1ovtml0v```

Here is my db.properties file

db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://okhuoxugkgndyv:42a41d66da81c48b4242a408f6f5ab95a8b6af21eb2150fed2b8c6cf50ef27a7@ec2-54-246-87-132.eu-west-1.compute.amazonaws.com:5432/de0n3c1ovtml0v
db.user=okhuoxugkgndyv
db.password=42a41d66da81c48b4242a408f6f5ab95a8b6af21eb2150fed2b8c6cf50ef27a7
db.poolSize=25
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${db.driver}"/>
        <property name="url" value="${db.url}"/>
        <property name="username" value="${db.user}"/>
        <property name="password" value="${db.password}"/>
    </bean>

In pom.xml I also have maven dependency.

<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
    <dependency>
      <groupId>postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>9.1-901-1.jdbc4</version>
    </dependency>

enter image description here

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
  • Checkout this post https://stackoverflow.com/questions/1911253/the-infamous-java-sql-sqlexception-no-suitable-driver-found – Nemanja Aug 24 '20 at 13:40
  • Have you tried a newer version of the PostgreSQL JDBC driver, version 9.1-901 is pretty old. See https://search.maven.org/artifact/org.postgresql/postgresql for latest version. – Mark Rotteveel Aug 24 '20 at 13:41
  • Pretty old? 2011. Thats almost 10 years! – Daniel Jacob Aug 24 '20 at 13:41
  • Thank you for showing us the user and password for your AWS database. Now go change them to something else. – Andreas Aug 24 '20 at 13:45

1 Answers1

0

It's not with jdbc drive it's due to properties are not able to find. As in your datasource configuration very first properties is driver and it's giving an error.

If you bring that line on second , you will get an error with URL.

You need to add db.property file name in you bean.xml file

<bean  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" scope="prototype">

    <property name="location">
        <value>classpath:/bundle/db.properties</value>
    </property>
</bean>

First try with static details as below. If it's work then try to bring those details from property file.

        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://localhost:5432/dbname" />
        <property name="username" value="postgres" />
        <property name="password" value="" />
Sagar Gangwal
  • 7,544
  • 3
  • 24
  • 38