我已经在我的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
连接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”,“斯科特”、“老虎”);
(删除@)
不知道为什么,但它现在工作了…
如果你使用Oracle Express Edition,你应该有这个url
jdbc:oracle:thin:@localhost:1521:xe或jdbc:oracle:thin:@localhost:1521/ xe
我在pom.xml中的liquibase配置插件中遇到了类似的问题。我改变了我的配置:
`<configuration>
<driver>oracle.jdbc.OracleDriver</driver>
<url>jdbc:oracle:thin:@localhost:1521:xe</url>
<defaultSchemaName></defaultSchemaName>
<username>****</username>
<password>****</password>
</configuration>`
我通过纠正JDBC代码解决了这个问题。
正确的JDBC字符串应该是…
conection = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","ishantyagi");
但是我使用的JDBC字符串是…
conection = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:orcl","system","ishantyagi");
因此,指定orcl而不是xe的错误显示了这个错误,因为SID名称是错误的。
当我试图使用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.