gpt4 book ai didi

java - 如何使用postgresql数据库在hibernate中获取远程端数据库的数据

转载 作者:行者123 更新时间:2023-12-01 09:56:56 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com