org.hibernate.exception.GenericJDBCException:无法打开连接 - Oracle / Tomcat / localhost

时间:2017-11-10 10:24:18

标签: java oracle hibernate

我正在用Oracle作为数据库编写一个简单的Hibernate程序 我面临这个错误,尽管进行了许多试验,但我无法得到解决方案 我添加了所有的休眠罐和放大器甲骨文(ojdbc14.jar)文件
我在Oracle数据库中有一个架构为“test”         用户名和& Oracle的密码是系统

我创建了以下文件:

  1. Student.java - POJO类,其字段为rollno,name,address&设置器/吸气剂
  2. Student.hbm.xml - 映射文件
  3. Student.cfg.xml - Hibernate配置文件
  4. Test.java - 驱动程序类
  5. Student.cfg.xml

    <?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>
            <property name = "connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
            <property name = "connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
            <property name = "username">system</property>
            <property name = "password">system</property>
    
            <property name = "show_sql">true</property>
            <property name = "dialect">org.hibernate.dialect.OracleDialect</property>
            <property name = "hbm2ddl.auto">update</property>
    
            <mapping resource = "com/alighthub/Student.hbm.xml"/>
        </session-factory>
    
        </hibernate-configuration>
    

    以下是错误:

        Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
            at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
            at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
            at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
            at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
            at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
            at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
            at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
            at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
            at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
            at com.alighthub.Test.main(Test.java:16)
        Caused by: java.sql.SQLException: invalid arguments in call
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:236)
            at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
            at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
            at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
            ... 5 more
    

    请建议。

1 个答案:

答案 0 :(得分:0)

用户名和&amp;属性密码在Student.cfg.xml中不正确,更新为&#34; connection.username&#34; &安培; &#34; connection.password&#34;如下: -

    <property name = "connection.username">system</property>
    <property name = "connection.password">system</property>