`

hibernate 下oralce数据库连接出问题

阅读更多
问题描述:
  初学hibernate 映射oralc10g数据库出现 The Network Adapter could not establish the connection oralce 错误。

  hibernate 配置文件如下:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521/oracle</property>
        <property name="connection.username">xxg</property>
        <property name="connection.password">xxg</property>

        <!-- JDBC connection pool (use the built-in) -->
      <!--   <property name="connection.pool_size">1</property> -->

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
    <!--      <property name="current_session_context_class">thread</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">update</property> -->

        <mapping resource="com/xxg/bean/Student.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


  
  解决办法:
   lz这样:开始--> 运行--> cmd--> netstat   -na
找找里面有没有如下一行:
TCP         127.0.0.1:1521                   0.0.0.0:0                             LISTENING

  出现错误时,我没找到。当把localhost 改成127.0.0.1时候解决问题了。
之后在改成localhost 时发现 错误也没出现。
  在这个过程之中添加了 Net Manager 的监听地址,主机名为:172.0.0.1, 端口号为:1521
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics