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

当前回答

我通过在TNSNAMES中将“SID”更改为“SERVICE_NAME”来修复这个问题。ora文件。

请查看您的DB是否要求SID或SERVICE_NAME。

干杯

其他回答

连接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”,“斯科特”、“老虎”);

(删除@)

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

当我使用以下代码时,我的问题得到了解决:

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@IPAddress:1521/servicename","userName","Password");

我也遇到过同样的问题,通过重新启动OracleServiceXE服务解决了这个问题。转到服务。然后验证“OracleServiceXE”服务是否正常运行

我只是通过在服务中重新启动oracleService来修复它

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

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

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