ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

引子:

本项目在老电脑上用的是oracle10g,换新电脑装的是oracle11g,但运行项目本没有什么关系,本来说创建个用户,用PLSQL手工导入数据,再改几下配置文件即可跑起来--但实际启动中遇到以下异常导致eclipse不能启动:

2016-01-25 11:34:39,694 DEBUG (com.mchange.v2.resourcepool.BasicResourcePool:1831) - An exception occurred while acquiring a poolable resource. Will retry.

java.sql.SQLException: Listener refused the connection with the following error:

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)

at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)

at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)

at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)

at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)

at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:

at oracle.net.ns.NSProtocol.connect(NSProtocol.java:385)

at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)

... 12 more

该异常属于第一次遇到,而且诡异的是,我用cmd面板、PLSQL、sqldeveloper 这几种方式连接都正常,唯独能不能再eclipse上连接,然后百度一搜,有很多答案,但基本上都是一个--修改Oracle的 listener.ora 文件,如下面的博文:

http://blog.csdn.net/hxl122lcq/article/details/7542462

但用此方法解决失败。用此方法的解决的所针对的版本的基本上都是10g的,我的是11g的,但应该不是这个原因引起解决失败的。

现在已经解决了,这是我当前的 listener.ora 文件:

# listener.ora Network Configuration File: D:\oracle11g\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = D:\oracle11g\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:D:\oracle11g\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = D:\oracle11g

上面是我现在的 listener.ora 文件,也是oracle11g默认的 listener.ora 文件,本来我已经用网上的方法把此文件修改成以下的配置:

# listener.ora Network Configuration File: D:\oracle11g\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = D:\oracle11g\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:D:\oracle11g\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
    (SID_DESC =
      (GLOBAL_DBNAME = ORCL)
      (ORACLE_HOME = D:\oracle11g\product\11.2.0\dbhome_1)
      (SID_NAME = ORCL)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.127.0.34)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = D:\oracle11g

注:红色字体为新增内容。

可是是什么时候它又恢复了默认配置?--我不得而知(我在改后应该没有进行恢复)。--不管它了,总之最重要的结论是:网上的这种解决方式并不能解决我的问题!那我是如何解决的呢?--其实我也不太清楚,应该是下面的某一节点、行为解决了此问题。下面是我的解决过程:

先贴出我的相关配置文件:

jdbc.properties   (注:用的是c3p0)

#hibernate.connection.provider_class=com.jolbox.bonecp.BoneCPDataSource
#hibernate.connection.provider_class=com.jolbox.bonecp.provider.BoneCPConnectionProvider
# c3p0
hibernate.connection.provider_class=com.mchange.v2.c3p0.ComboPooledDataSource
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
#hibernate.connection.url=jdbc\:oracle\:thin\:@116.252.178.236\:1521\:orcl
hibernate.connection.url=jdbc\:oracle\:thin\:@localhost\:1521\:orcl
hibernate.connection.username=mynewdpi
hibernate.connection.password=root

bonecp.idleMaxAge=6
bonecp.idleConnectionTestPeriod=6
bonecp.partitionCount=3
bonecp.acquireIncrement=5
bonecp.maxConnectionsPerPartition=6
bonecp.minConnectionsPerPartition=2
bonecp.statementsCacheSize=5
bonecp.releaseHelperThreads=3
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.use_query_cache=true

applicationContext.xml

     <!--配置bonecp连接池 -->
    <bean id="dataSource" class="${hibernate.connection.provider_class}" >
        <property name="driverClass" value="${hibernate.connection.driver_class}" />
        <property name="jdbcUrl" value="${hibernate.connection.url}" />
        <property name="user" value="mynewdpi"/>
        <property name="password" value="root"/>
    </bean>

1.配置SID的环境变量

在环境变量里面的系统变量新建ORACLE_SID
新建这个环境变量  值为orcl

注:至此启动项目,异常依旧。

2.拿一个oracle小项目做实验进行连接。

这是我下载一个简单的用户登录、管理的小项目下载地址:http://download.csdn.net/download/zxl07370330/3469358

把它放到eclipse上,创建用户,一个用户及一条数据,登录成功!

至此再启动项目,连接成功!

小结:很多时候,我们在网上找答案,一般来说,搜索最多的答案成功几率是最大的--但事实不总是这样。有时候,凭直觉和经验你会知道某个答案是比较靠谱的,虽然它并不是头条。有时候你的问题并不属于那些回答最多的答案,那么你的答案是什么--还得说靠自己的动手实践。本篇博客看下来应该是一件很简单的事情,但大多时间都是按照网上说的那条搞来搞去也没搞出来--总之最后的答案是与 listener.ora 文件无关,但要说是与SID的环境变量的设置有关--但我设置完重启eclipse也不行啊,为什么先连个小项目后成功,再连大项目也成功呢?我不得而知,现在只能在最后给自己的一个推测:

本来按照网上的做法修改listener.ora 文件是不成功的,再增加SID环境变量也不成功,后来在连接小项目时应该是把listener.ora 文件恢复成了默认配置,再加上SID的环境变量的设置,因此成功了。

时间: 2024-12-20 02:36:30

ORA-12505, TNS:listener does not currently know of SID given in connect descriptor的相关文章

连接oracle数据库出现:ORA-12505,TNS:listener does not currently know of SID given in connect descriptor

Java使用 jdbc:oracle:thin:@11.1.0.14:1521:orcl 连接oracle数据库出现: ORA-12505,TNS:listener does not currently know of SID given in connect descriptor 错误. 表明服务器上sid为orcl的服务并不存在,可以换个方式直接连接服务:把最后一个冒号换为斜杠.顺利连上数据库 jdbc:oracle:thin:@11.1.0.14:1521/orcl

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

问题描述: 在使用JDBC连接数据库的时候,报错: 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 解决方案: 经检查,是由于连接的URL写错导致,原URL:"jdbc:oracle:thin:@localhost:152

TNS-12505: TNS:listener does not currently know of SID given in connect descriptor

oracle中log.xml报错信息 plsql登录报错信息: 无法请求描述符中的服务 百度了很多,都是一种处理方法,可是对我这里完全不管用,下面是我遇到的两次异常的解决方法: 1.看/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora这个配置文件 # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/ne

解决Oracle ORA-12505, TNS:listener does not currently know of SID given in connect(转)

http://anthon-lx.iteye.com/blog/811460 完整的错误信息如下: 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 th

解决Oracle ORA-12505, TNS:listener does not currently know of SID given in connect

完整的错误信息如下: 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: 192.168.149.128:1521:orcl

listener does not currently know of SID given in connect descriptor

一次连接数据库怎么也连接不上,查了多方面资料,终于找到答案,总结 首先应该保证数据库的服务启动 在myeclipse的数据库视图中点 右键->new 弹出database driver的窗口, Driver template选择oracle(thin driver), Driver name 输入oracle   connection URL=jdbc:oracle:thin:@localhost:1521:oracle 注意localhost:1521:oracle中的oracle是数据库得s

ORA-12505, TNS:listener does not currently know of SID given in connect desc .

这种情况一般因为数据库的实例名没有给,只给了数据库的服务名 什么是数据库实例名?  数据库实例名是用于和操作系统进行联系的标识,就是说数据库和操作系统之间的交互用的是数据库实例名.实例名也被写入参数文件中,该参数为instance_name,在winnt平台中,实例名同时也被写入注册表.  数据库名和实例名可以相同也可以不同.  在一般情况下,数据库名和实例名是一对一的关系,但如果在oracle并行服务器架构(即oracle实时应用集群)中,数据库名和实例名是一对多的关系. 这种情况一般因为数据

ORA-12514: TNS: listener does not currently know of service requested in connect descriptor

1. 环境: oracle 11g x64 2. sqlplus 可以正常使用,PLSQLDeveloper登录出错如下: 2. 解决方法:参考http://www.linuxidc.com/Linux/2012-09/69678.htm

ORA-12514: TNS:listener does not currently know of service requested in connect

1,登录报错如下: [oracle@oracle_yueworld admin]$ rlwrap sqlplus system/system51@st1 SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 3 16:33:26 2015 Copyright (c) 1982, 2009, Oracle. All rights reserved. ERROR: ORA-12514: TNS:listener does not currently k