Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get JDBC connection with PostgreSQL

I am trying to get a JDBC connection to PostgreSQL. Driver version in dependency is: 9.4-1204-jdbc42 and Postgres version is 9.5.0. Following is the stack:

Caused by: java.lang.UnsupportedClassVersionError: org/postgresql/Driver : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:127)
    at com.biginfolabs.ipmonitor.core.config.HibernateConfiguration.dataSource(HibernateConfiguration.java:41)
    at com.biginfolabs.ipmonitor.core.config.HibernateConfiguration$$EnhancerByCGLIB$$a2cde1cc.CGLIB$dataSource$2(<generated>)
    at com.biginfolabs.ipmonitor.core.config.HibernateConfiguration$$EnhancerByCGLIB$$a2cde1cc$$FastClassByCGLIB$$17817301.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:326)
    at com.biginfolabs.ipmonitor.core.config.HibernateConfiguration$$EnhancerByCGLIB$$a2cde1cc.dataSource(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    ... 49 more

Please suggest what is the issue here?

like image 208
Manoj Suthar Avatar asked Jan 15 '16 17:01

Manoj Suthar


People also ask

Does JDBC work with PostgreSQL?

The PostgreSQL JDBC Driver allows Java programs to connect to a PostgreSQL database using standard, database independent Java code. pgJDBC is an open source JDBC driver written in Pure Java (Type 4), and communicates in the PostgreSQL native network protocol.

Where is PostgreSQL JDBC driver located?

After installation, the driver should be found in PREFIX/share/java/postgresql. jar.


2 Answers

"unsupported major.minor version 52" says that you must use java8 and are running in java7 or lower.

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

9.4-1204-jdbc42 is the driver compiled in java8.

9.4-1204-jdbc41 is the driver compiled in java7.

9.4-1204-jdbc4 is the driver compiled in java6.

like image 50
Christoph-Tobias Schenke Avatar answered Sep 30 '22 15:09

Christoph-Tobias Schenke


The PostgreSQL driver you're using is built for Java 1.8, but you're not running Java 1.8 - probably you're running Java 1.7

Either upgrade to Java 1.8 or use the postgresql-9.4.1207.jre7.jar file that works with Java 1.7 (as you can see here )

like image 35
nos Avatar answered Sep 30 '22 14:09

nos