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

当前回答

如果您在Oracle SQL Developer中有一个工作连接,请使用连接菜单上的信息来构建您的url,如下图所示:

在上面的例子中,url将是:jdbc:oracle:thin:@ORADEV.myserver.com:1521/myservice

注意,如果您使用的是SID,那么在主机名后面有一个冒号(“:”)而不是斜杠(“/”)。

其他回答

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.

我通过纠正jdbc字符串解决了这个问题。

例如,正确的jdbc字符串应该是…

jdbc:oracle:thin:@myserver:1521/XE

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

jdbc:oracle:thin:@myserver:1521:XE

(注:在1521和XE之间应该是a /)

这个糟糕的jdbc字符串也给了我一个ORA-12505错误。

当你浏览start->run->services.msc时,请检查OracleServiceXE和OracleXETNSListener的状态是否已启动。

对于我的情况下,只有OracleXETNSListener启动,但OracleServiceXE没有启动,当我开始右键单击->启动并检查连接它为我工作

@Luke Woodward的回答帮助我确定我的XE没有连接。 我在连接VPN时遇到了一个问题。我使用的是Windows 11上的最新本地Oracle 21c。 文件监听器。Ora和tnsnames。我们使用我的电脑名称“ERIK-PC”是这样的:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ERIK-PC)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

我只需要将ERIK-PC更改为localhost。 更多信息在这个帖子里。 顺便说一下,我使用的是Oracle 21c,从18c开始,*。ora文件在installationfolder\homes\OraDB21Home1\network\admin\*.ora下 保存您的更改并使用特权的windows shell重新启动侦听器:

lsnrctl stop
lsnrctl start

我也遇到过类似的问题。问题开始突然发生-我们有负载平衡的数据库连接URL,但在jdbc连接中,我直接指向一个db。

更改为负载平衡的db url和它的工作。