简体   繁体   中英

No suitable driver found for jdbc:postgresql:

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>

在此处输入图片说明

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="" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM