简体   繁体   English

Hibernate无法打开与Oracle 11g的连接?

[英]Hibernate fails to open Connection with Oracle 11g?

I made a basic JUnit test to set up this Oracle database on my computer with hibernate. 我做了一个基本的JUnit测试,用hibernate在我的计算机上设置这个Oracle数据库。 The database works and everything, but trying to hook it up to Hibernate is proving to be a challenge. 数据库可以工作,但是试图将它连接到Hibernate被证明是一个挑战。 My config file can be here : 我的配置文件可以在这里

The JUnit test is fairly straight forward and I'm sure it should work, but I'm getting this JUnit failure: JUnit测试相当简单,我确信它应该可以正常工作,但我得到了这个JUnit失败:

 org.hibernate.exception.JDBCConnectionException: Cannot open connection 

Any ideas what's wrong with it? 有什么想法吗?

Connection properties in Hibernate config file: Hibernate配置文件中的连接属性:

<session-factory>
    <property name="hibernate.connection.driver_class">
        oracle.jdbc.OracleDriver</property>
    <property name="hibernate.connection.url">
        jdbc:Oracle:thin:@127.0.0.1:8080/slyvronline</property>
    <property name="hibernate.connection.username">
        YouNoGetMyLoginInfo</property>
    <property name="hibernate.connection.password">
        YouNoGetMyLoginInfo</property>
    <property name="dialect">
        org.hibernate.dialect.OracleDialect</property>
    <!-- Other -->
    <property name="show_sql">true</property>
    <property name="hibernate.hbm2ddl.auto">validate</property>

    <!-- Mapping files -->
    <mapping class="com.slyvr.pojo.Person"/>
</session-factory>

It's unlikely (but possible) your DB is listening on port 8080. Oracle defaults to port 1521. Start there. 您的数据库不太可能(但可能)正在侦听端口8080.Oracle默认为端口1521.从那里开始。

(Since it's a connection issue, relevant portions of Hibernate config are useful; I've edited to reflect.) (因为这是一个连接问题,Hibernate配置的相关部分很有用;我已编辑反映。)

There are possible two issues in your connection string 您的连接字符串中可能存在两个问题

first is the port that Dave Newton, second that after port you should add the sid after : not /. 第一个是Dave Newton的端口,第二个是端口后你应该添加sid:not /。

So try this as a solution: 所以尝试这个解决方案:

jdbc:Oracle:thin:@127.0.0.1:1521:slyvronline

When you are connecting with oracle, no need to mention the schema name so the connection URL looks like as below 当您使用oracle连接时,无需提及架构名称,因此连接URL如下所示

    jdbc:oracle:thin:@<hostname>:<port>:<sid>
    ex:
    jdbc:oracle:thin:@localhost:1521:xe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM