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

当前回答

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

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

其他回答

当你得到这个错误“ORA-12505, TNS:监听器目前不知道在连接描述符中给定的SID”

解决方案:打开服务,启动OracleServiceXE,然后尝试连接…

除了运行服务(OracleServiceXE,OracleXETNSListener)之外,您的防病毒软件/防火墙可能仍然会阻止它们。只要确保它们没有被阻挡。

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

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

连接con = DriverManager.getConnection (" jdbc: oracle:薄:@localhost: 1521: xe”,“斯科特”、“老虎”);

我得到的错误:

java.sql.SQLException:监听器拒绝连接,错误如下: ORA-12505, TNS:监听器当前不知道连接描述符中给定的SID 客户端使用的连接描述符是: localhost: 1521: xe

我是怎么解决的:

连接con = DriverManager.getConnection (" jdbc: oracle:薄:localhost: 1521: xe”,“斯科特”、“老虎”);

(删除@)

不知道为什么,但它现在工作了…

我还没有看到广泛讨论的一种可能性是,在主机上解析主机名本身可能存在问题。如果在/etc/hosts中没有$(hostname)条目,Oracle侦听器会感到困惑,不会出现。

这原来是我的问题,在/etc/hosts中添加主机名和ip地址解决了这个问题。