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

当前回答

我也得到了同样的错误,但当他们尝试所有三个失败。 如果以上三点都失败了。尝试LSNRCTL状态,如果您发现服务(在我的情况下是XE)丢失尝试这个

sqlplus /nolog
conn  system
alter system register;  
exit  
lsnrctl status  

现在您可以看到服务 即使没看到也试试这个

sqlplus /nolog  
conn system  
alter system set local_listener = '(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' scope = both;  
alter system register;  
exit  
lsnrctl status

这应该可以工作…

其他回答

我也得到了同样的错误,但当他们尝试所有三个失败。 如果以上三点都失败了。尝试LSNRCTL状态,如果您发现服务(在我的情况下是XE)丢失尝试这个

sqlplus /nolog
conn  system
alter system register;  
exit  
lsnrctl status  

现在您可以看到服务 即使没看到也试试这个

sqlplus /nolog  
conn system  
alter system set local_listener = '(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' scope = both;  
alter system register;  
exit  
lsnrctl status

这应该可以工作…

当我试图使用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.

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

(删除@)

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

通过在主机上执行tnsping和实例名来检查。它会给你tns描述,大多数时候主机名是不同的,不匹配。

我同样解决我的问题

在Unix机器中 $ tnspring(输入)

它给了我完整的tns描述,我发现主机名是不同的..:)

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

URL:

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

是行不通的。

URL:

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

的工作原理。

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