我已经在我的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: 精简样式的服务名称语法

只有JDBC Thin驱动程序支持精简样式的服务名称。语法为:

/ service_name @ / / host_name: port_number进行

http://docs.oracle.com/cd/B28359_01/java.111/b31224/urls.htm#BEIDHCBA

其他回答

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

URL:

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

是行不通的。

URL:

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

的工作原理。

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

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

连接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地址解决了这个问题。

我也有同样的问题,所以为了解决这个问题,我首先使用netca重新配置我的侦听器,之后我删除了我的旧数据库,这是ORCL使用dbca,然后我再次使用dbca创建了新的数据库