RVA
RVA

Reputation: 870

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.postgresql.Driver'

I'm having trouble to migrate from an oracle db web-app context to a postgresql db web-app context.

I'm having a simple java spring-mvc web-app with flyway to init the database process and hibernate to manage objects. This web-app was initialiy think to use a oracle database and I'm trying to use a postgresql base instead, but I'm pretty new with this base and not confortable with the declaration of the datasource. May be you will find what's wrong.

I'm using tomcat apache server (v6) within eclipse plugin to debug my webapp.

When I'm trying to run my web-app on my server, the server failed to start with this log :

11:23:57.903 [main] INFO  o.h.tool.hbm2ddl.SchemaUpdate - HHH000228: Running hbm2ddl schema update
11:23:57.903 [main] INFO  o.h.tool.hbm2ddl.SchemaUpdate - HHH000102: Fetching database metadata
11:23:57.903 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - HHH000319: Could not get database metadata
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.postgresql.Driver'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136) ~[tomcat-dbcp.jar:na]
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) ~[tomcat-dbcp.jar:na]
[...]
Caused by: java.lang.UnsupportedClassVersionError: org/postgresql/Driver : Unsupported major.minor version 51.0

I've add the driver to my pom.xml

   <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1200-jdbc41</version>
    </dependency>

and made the

   mvn eclipse:eclipse 

I'm using a datasource declared in my META-INF directory :

   <Context>
      <Resource name="jdbc/BlankAppDataSource"
        auth="Container"
        type="javax.sql.DataSource"
        username="postgres"
        password="postgres"
        driverClassName="org.postgresql.Driver"
        url="jdbc:postgresql://localhost:5432/my_schema" 
/>

I've even added the driver .jar to my tomcat lib directory (CATALINA_HOME/lib).

Thanks by advance.

Regards, Romain.

Upvotes: 3

Views: 7394

Answers (2)

Leonardo Nogueira
Leonardo Nogueira

Reputation: 56

I had the same problem and in my case, i just inserted the lib "postgresql-8.0-314jdbc3.jar" in the "apache-tomcat-6.0.44/lib" folder and it ran perfectly.

I'm using the JDK 1.8.0_60 in Tomcat Server Runtime Environment.

Upvotes: 4

DanielFo1.
DanielFo1.

Reputation: 39

"Unsupported major.minor version 51.0" means maven has downloaded class files compiled for Java1.7 ( look at ClassVersionChecker).

Now upgrade the JavaVM your Tomcat is using to at least 1.7! You will find a line like

catalina.startup.VersionLogger.. JVM Version: 1.7.0_76-b13

in your $TOMCAT_HOME/logs/catalina.out file.

Upvotes: 0

Related Questions