java.sql.SQLException:侦听器拒绝连接并出现以下错误:ORA-12505
Posted
技术标签:
【中文标题】java.sql.SQLException:侦听器拒绝连接并出现以下错误:ORA-12505【英文标题】:java.sql.SQLException: Listener refused the connection with the following error: ORA-12505 【发布时间】:2017-08-07 06:49:04 【问题描述】:嗨,我是初学者,目前我已经在我的 Windows 7 64 位操作系统中安装了 Oracle 10g Express Edition Release 2 并尝试执行 Hibernate 程序,但我遇到了异常情况,请有人帮助我
WARNING: Could not obtain connection metadata
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:xe
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
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(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
at test.Test.main(Test.java:11)
hibernate.cfg.xml:-
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/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="connection.username">scott</property>
<property name="connection.password">tiger</property>
<property name="connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping resource = "resources/Dept.hbm.xml"/>
<mapping resource = "resources/Employee.hbm.xml"/>
<mapping resource = "resources/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
【问题讨论】:
在windows中进入Services查看OracleXETNSListener和OracleServiceXE是否处于运行状态。 在服务选项卡中没有用于运行它的 OracleServiceXE 选项 让我们continue this discussion in chat. 【参考方案1】:说明你的实例名是xe,确定xe是你安装的实例。
如果没有,请更改实例名称。
不是服务器名称。
【讨论】:
如何找到实例名称?【参考方案2】:错误消息显示给定的 SID 未知。请通过连接到任何架构并运行以下任何查询来确保已安装实例的 SID 为“xe”
select instance from v$thread;
select name from v$database;
或在sqlplus
命令提示符下输入
show parameter instance_name;
【讨论】:
以上是关于java.sql.SQLException:侦听器拒绝连接并出现以下错误:ORA-12505的主要内容,如果未能解决你的问题,请参考以下文章
java.sql.SQLException:getShort() 的值无效 - ''
java.sql.SQLException: SQL 语句在 org.hsqldb.jdbc.JDBCUtil.sqlException 处关闭
Oracle DB:java.sql.SQLException:关闭连接
Cause: java.sql.SQLException: 请求的转换无效 ; uncategorized SQLException for SQL []; SQL state [99999]; er