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:

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

 

    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:

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

 

    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的环境变量的设置,因此成功了。

 

 

posted @ 2016-01-26 16:55  Tom1997  阅读(5816)  评论(0编辑  收藏  举报