Java 无法建立JDBC连接[JDBC:postgres://localhost:5432/hibernatedb]
我正在尝试使用数据库制作一个软件,经过多次尝试后,我遵循了一个原则 我正在使用Java8、PostgreSQL9.4和Hibernate5.2.2(加上JBossTools4.4.1) 在运行应用程序之前,我一直遵循教程,但随后出现以下错误消息,说明应用程序无法连接到数据库:Java 无法建立JDBC连接[JDBC:postgres://localhost:5432/hibernatedb],java,postgresql,hibernate,jdbc,Java,Postgresql,Hibernate,Jdbc,我正在尝试使用数据库制作一个软件,经过多次尝试后,我遵循了一个原则 我正在使用Java8、PostgreSQL9.4和Hibernate5.2.2(加上JBossTools4.4.1) 在运行应用程序之前,我一直遵循教程,但随后出现以下错误消息,说明应用程序无法连接到数据库: oct. 15, 2016 2:53:35 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.2.2.Final} oct. 15
oct. 15, 2016 2:53:35 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.2.Final}
oct. 15, 2016 2:53:35 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
oct. 15, 2016 2:53:35 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
oct. 15, 2016 2:53:35 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
oct. 15, 2016 2:53:36 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
oct. 15, 2016 2:53:36 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgres://localhost:5432/hibernatedb]
oct. 15, 2016 2:53:36 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=postgresql, password=****}
oct. 15, 2016 2:53:36 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
oct. 15, 2016 2:53:36 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
at com.kg.hibernate.main.HibernateTest.main(HibernateTest.java:16)
Caused by: org.hibernate.HibernateException: Unable to make JDBC Connection [jdbc:postgres://localhost:5432/hibernatedb]
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:60)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:123)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:42)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:20)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:161)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:109)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:72)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257)
... 14 more
UserDetails.java
package com.kg.hibernate;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class UserDetails {
@Id
private int userId;
private String userName;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database Connection settings -->
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">kgware</property>
<property name="hibernate.connection.url">jdbc:postgres://localhost:5432/hibernatedb</property>
<property name="hibernate.connection.username">postgresql</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Names the annotated entity class -->
<mapping class="com.kg.hibernate.UserDetails"/>
</session-factory>
</hibernate-configuration>
org.postgresql.Driver
kgware
jdbc:postgres://localhost:5432/hibernatedb
postgresql
org.hibernate.dialogue.PostgreSqlDialogue
1.
org.hibernate.cache.NoCacheProvider
真的
创造
我在许多论坛上搜索了一个解决方案,但没有找到任何
谢谢你的帮助 您的连接字符串是错误的
<property name="hibernate.connection.url">jdbc:postgres://localhost:5432/hibernatedb</property>
jdbc:postgres://localhost:5432/hibernatedb
到
jdbc:postgresql://localhost:5432/hibernatedb
您的连接字符串是错误的
<property name="hibernate.connection.url">jdbc:postgres://localhost:5432/hibernatedb</property>
jdbc:postgres://localhost:5432/hibernatedb
到
jdbc:postgresql://localhost:5432/hibernatedb
在连接url值中,尝试将“jdbc:postgres”更改为“jdbc:postgresql”。我希望这对你有帮助。哎呀,这样一个小错误。。。非常感谢!有时您需要其他人来找到它…在您的连接url值中,尝试将“jdbc:postgres”更改为“jdbc:postgresql”。我希望这对你有帮助。哎呀,这样一个小错误。。。非常感谢!有时候你需要别人来发现…奇怪。。。EclipseLink使用“postgres”,现在切换到Hibernate,现在需要“postgresql”。。无论如何现在它工作了。奇怪。。。EclipseLink使用“postgres”,现在切换到Hibernate,现在需要“postgresql”。。无论如何现在它起作用了。
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>