我已经在我的windows 7 64位操作系统中安装了Oracle 11g Express Edition Release 2,并试图执行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
    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 java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.jlcindia.jdbc.JDBCUtil.geOracleConnection(JDBCUtil.java:28)
    at Lab3O.main(Lab3O.java:15)
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)
    ... 8 more

当前回答

我通过纠正JDBC代码解决了这个问题。

正确的JDBC字符串应该是…

conection = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","ishantyagi");

但是我使用的JDBC字符串是…

conection = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:orcl","system","ishantyagi");

因此,指定orcl而不是xe的错误显示了这个错误,因为SID名称是错误的。

其他回答

面对类似的错误,上述任何解决方案都不起作用。 监听器有问题。ora文件。我错误地添加了SID的SID_LIST见下面(部分之间的星星*)。

 SID_LIST_LISTENER =
      (SID_LIST =

        (SID_DESC =
          (SID_NAME = PLSExtProc)
          (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
          (PROGRAM = extproc)
        )
        (SID_DESC =
          (SID_NAME = CLRExtProc)
          (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
          (PROGRAM = extproc)
        )
        )

 *(SID_DESC =
           (SID_NAME = XE)
           (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
         )*
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
          (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
        )
      )


    DEFAULT_SERVICE_LISTENER = (XE)

更正此错误如下:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
       (SID_NAME = XE)
       (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
     )
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
      (PROGRAM = extproc)
    )
    )
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    )
  )


DEFAULT_SERVICE_LISTENER = (XE)

停止,数据库

手动停止监听器OracleServiceXE和OracleXETNSListener,因为它没有通过进入控制面板\所有控制面板项\管理工具\服务自动停止。重新启动数据库,它工作得很好。

如果你使用Oracle Express Edition,你应该有这个url

jdbc:oracle:thin:@localhost:1521:xe或jdbc:oracle:thin:@localhost:1521/ xe

我在pom.xml中的liquibase配置插件中遇到了类似的问题。我改变了我的配置:

`<configuration>
   <driver>oracle.jdbc.OracleDriver</driver>
   <url>jdbc:oracle:thin:@localhost:1521:xe</url>
   <defaultSchemaName></defaultSchemaName>
   <username>****</username>
   <password>****</password>
</configuration>`

I too faced the same issue. I had installed Oracle Express edition 10g in Windows XP OS using VMware and it was working fine. Since it was very awkward typing SQL queries in the SQL utility provided by 10g and since I was used to working with SQL developer, I installed 32 bit SQL developer in XP and tried connecting to my DB SID "XE". But the connection failed with error-ORA-12505 TNS listener doesn't currently know of SID given in connect descriptor. I was at sea as to how this problem occurred since it was working fine with the SQL utility and I had also created few Informatica mappings using the same. I did browse a lot on this stuff hither thither and applied the suggestions offered to me after pinging the status of "lsnrctl" on public forums but to no avail. However, this morning I tried creating a new connection again, and Voila, it worked with no issues. I am guessing after reading in few posts that sometimes listener listens before the DB connects or something(pardon me for my crude reference as I am a newbie here) but I suggest to just restart the machine and check again.

Oracle: 精简样式的服务名称语法

只有JDBC Thin驱动程序支持精简样式的服务名称。语法为:

/ service_name @ / / host_name: port_number进行

http://docs.oracle.com/cd/B28359_01/java.111/b31224/urls.htm#BEIDHCBA

我也有同样的问题,所以为了解决这个问题,我首先使用netca重新配置我的侦听器,之后我删除了我的旧数据库,这是ORCL使用dbca,然后我再次使用dbca创建了新的数据库