0

Am getting the error while trying to communicate with the PostgreSQL.

The error I am getting is Could not load requested class : org.postgresql.Driver

Another error I get is java.sql.SQLException: Unable to load class: org.postgresql.Driver from ClassLoader:sun.misc.Launcher$AppClassLoader

My application.properties file looks like this:

spring.ds_items.driverClassName=org.postgresql.Driver 
spring.ds_items.url=jdbc:postgresql://localhost:5432/Dummy
spring.ds_items.username=root
spring.ds_items.password=root 
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create

spring.ds_users.driverClassName=org.postgresql.Driver 
spring.ds_users.url=jdbc:postgresql://localhost:5432/Dummy2 
spring.ds_users.username=root
spring.ds_users.password=root
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create

and my build.gradle file dependencies looks like this ,

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('mysql:mysql-connector-java:5.1.38')
    sql ('org.postgresql:postgresql-9.1-901-1.jdbc4')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
}

What am I doing wrong, and how can I fix it?

4
  • 2
    Add the jar containing the driver... Commented Jun 16, 2016 at 12:08
  • If you are using Maven, add the Postgres driver to your dependencies Commented Jun 16, 2016 at 12:51
  • Am using Gradle !! Commented Jun 16, 2016 at 12:53
  • Are you sure there is a postgresql-9.1-901-1.jdbc4 dependency? The latest 9.1 build is 903 not 901 (and why are you using such an outdated driver?) Commented Jun 16, 2016 at 13:41

3 Answers 3

2

Add dependency:

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.1.4</version>
</dependency>   
Sign up to request clarification or add additional context in comments.

Comments

1

Make sure there is no trailing whitespace for any of your application properties.

I ran into this on a new project, and was receiving the exact same error. I was pulling my hair out for hours until I realized that simple mistake.


If this doesn't do the trick then perhaps share a sample project on GitHub?

Comments

0

Does your project include the appropriate driver .jar file?
Check here:

https://jdbc.postgresql.org/download.html

It should go in your application's lib/ directory, probably in WEB-INF/lib.

5 Comments

Sorry, for some reason I assumed you were running a Tomcat server. It should go in your application's lib folder, probably in WEB-INF/lib or something. Wherever .jars normally go in your application.
Yah i done that also, But still it says ( org.hibernate.tool.hbm2ddl.SchemaExport : HHH000231: Schema export unsuccessful ) and ( Could not load requested class : org.postgresql.Driver )
Can you tell me the path you added the .jar to, and which version you used? Make sure the permissions are OK on it? If you're on a Mac/Linux distro, run sudo chmod 777 postgresql_file_name_here.jar to make sure it can be accessed.
I edited my code, have a Look on Dependencies , Was i done any mistakes there ?
I don't think so - the postgresql driver you downloaded matches the version listed there under the sql dependency?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.