【问题标题】:how to fetch data of remote side database in hibernate using postgresql database如何使用 postgresql 数据库在休眠中获取远程端数据库的数据
【发布时间】:2016-05-10 12:15:07
【问题描述】:

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

【问题讨论】:

  • 把主机的IP放在DB所在的地方
  • 是的,我只给了 HostIP...仍然抛出 org.postgresql.util.psqlexception 连接被拒绝
  • 请检查主机名和端口是否正确
  • 尝试从您的机器连接,然后检查代码
  • 有效吗?或使用我的 xml

标签: java database hibernate postgresql


【解决方案1】:

hibernate.cfg.xml下方尝试并将HOSTIP更改为您的主机IP,其中存在DB。和DATABASENAME 与您的数据库名称和usernamepassword 相应。

<!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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    • 2015-08-04
    • 2016-10-04
    • 2017-05-09
    相关资源
    最近更新 更多