我正在使用 Postgresql 数据库。我需要知道如何在 hibernate.cfg.xml 中提供远程连接的连接 url。我给出了下面的行。但我无法从数据库检索数据。
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://hostIP:5432/databasename</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">password</property>
最佳答案
尝试下面的hibernate.cfg.xml
并将HOSTIP
更改为数据库所在的主机IP。以及DATABASENAME
相应的数据库名称以及用户名
和密码
。
<!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>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:postgresql://HOSTIP:5432/DATABASENAME</property>
<property name="connection_pool_size">1</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping class="org.javabrains.sanjaya.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>
关于java - 如何使用postgresql数据库在hibernate中获取远程端数据库的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37138256/