简体   繁体   English

无法与PostgreSQL建立JDBC连接

[英]Unable to get JDBC connection with PostgreSQL

I am trying to get a JDBC connection to PostgreSQL. 我试图获得与PostgreSQL的JDBC连接。 Driver version in dependency is: 9.4-1204-jdbc42 and Postgres version is 9.5.0. 依赖的驱动程序版本是:9.4-1204-jdbc42和Postgres版本是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? 请在这里建议问题是什么?

"unsupported major.minor version 52" says that you must use java8 and are running in java7 or lower. “不支持的major.minor版本52”说你必须使用java8并且在java7或更低版​​本中运行。

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

9.4-1204-jdbc42 is the driver compiled in java8. 9.4-1204-jdbc42是用java8编译的驱动程序。

9.4-1204-jdbc41 is the driver compiled in java7. 9.4-1204-jdbc41是java7中编译的驱动程序。

9.4-1204-jdbc4 is the driver compiled in java6. 9.4-1204-jdbc4是java6中编译的驱动程序。

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 您正在使用的PostgreSQL驱动程序是为Java 1.8构建的,但您没有运行Java 1.8 - 可能您正在运行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 ) 升级到Java 1.8或使用适用于Java 1.7的postgresql-9.4.1207.jre7.jar文件(如此处所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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