我已经在我的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

当前回答

我刚来的时候也有同样的问题。我刚刚在Windows 8(64位)上安装了Oracle 12c,但我已经在命令行上通过'TNSPING xe'解决了它…如果连接未建立或名称未找到,请尝试数据库名称,在我的情况下,它是'orcl'…再次使用' tnspring orcl',如果它ping成功,那么你需要在这种情况下将SID更改为'orcl'(或任何你使用的数据库名称)…

其他回答

当我试图使用SQL开发器连接到oracle DB时,我得到了这个错误ORA-12505, TNS:侦听器目前不知道连接描述符中给定的SID。

使用的JDBC字符串是JDBC:oracle:thin:@myserver:1521/XE,显然是正确的,两个强制的oracle服务OracleServiceXE, OracleXETNSListener已经启动并运行。

我解决这个问题的方法(在Windows 10中)

 1. Open run command.
 2. Type services.msc 
 3. Find services with name OracleServiceXE and OracleXETNSListener in the list.
 4. Restart OracleServiceXE service first. After completing the restart try restarting OracleXETNSListener service.

我刚来的时候也有同样的问题。我刚刚在Windows 8(64位)上安装了Oracle 12c,但我已经在命令行上通过'TNSPING xe'解决了它…如果连接未建立或名称未找到,请尝试数据库名称,在我的情况下,它是'orcl'…再次使用' tnspring orcl',如果它ping成功,那么你需要在这种情况下将SID更改为'orcl'(或任何你使用的数据库名称)…

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”任务。 要修复它,你需要打开cmd ->类型:服务。>找到服务“OracleServiceXE”->右键单击:启动。

我在SQL Workbench中也遇到过类似的问题。

URL:

jdbc: oracle:薄:@111.111.111.111:1111:xe

是行不通的。

URL:

jdbc: oracle:薄:@111.111.111.111:1111:asdb

的工作原理。

这对我的具体情况有帮助。恐怕还有许多其他的原因和不同的解决办法。