Manoj Suthar
Manoj Suthar

Reputation: 1455

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?

Upvotes: 8

Views: 15602

Answers (2)

Christoph-Tobias Schenke
Christoph-Tobias Schenke

Reputation: 3300

"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.

Upvotes: 11

nos
nos

Reputation: 229342

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 )

Upvotes: 4

Related Questions