Java ORA-12505 :TNS 侦听器当前不知道连接描述符中给出的 SID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30861061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORA-12505 :TNS listener does not currently know of SID given in connect descriptor
提问by Rajesh Koppala
I am using Oracle database. I've written a small JDBC connection program in Java but I am facing an issue with the listener.
我正在使用 Oracle 数据库。我已经用 Java 编写了一个小型 JDBC 连接程序,但是我遇到了侦听器的问题。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JdbcConnection {
public static void main(String[] args) throws SQLException,ClassNotFoundException {
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "system";
String password = "password";
Connection connection = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(url, user, password);
if(connection!=null){
System.out.println("Success in connnection");
} else {
System.out.println("failure in connection ");
}
}
}
I am getting the following exception:
我收到以下异常:
C:\Users\Administrator\Desktop>java JdbcConnection
Exception in thread "main" java.sql.SQLException: Listener refused the connectio
n with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:orcl
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:261)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
441)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensio
n.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JdbcConnection.main(JdbcConnection.java:18)
This is the output of lsnrctl status
这是输出 lsnrctl status
LSNRCTL for 64-bit Windows: Version 12.1.0.1.0 - Production on 16-JUN-2015 13:43
:41
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 64-bit Windows: Version 12.1.0.1.0 - Produ
ction
Start Date 16-JUN-2015 12:02:52
Uptime 0 days 1 hr. 40 min. 52 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File C:\app\orauser\product.1.0\dbhome_1\network\admin\l
istener.ora
Listener Log File C:\app\orauser\diag\tnslsnr\hydwemvm\listener\alert\lo
g.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\.\pipe\EXTPROC1521ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hydwemvm)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
回答by Ravi
If you know your oracle database SID, then use
如果您知道您的 oracle 数据库 SID,则使用
jdbc:oracle:thin:@localhost:1521:orcl
otherwise use below in case you have service name
否则,如果您有服务名称,请在下面使用
jdbc:oracle:thin:@localhost:1521/orcl
Also, make sure service name with the name ORCL
should be up and running. If still doesn't work, then you need to restart your machine and try again above.
此外,请确保具有该名称的服务名称ORCL
应已启动并正在运行。如果还是不行,那么你需要重新启动你的机器并在上面重试。
Still, not working ?Then, try following :
还是行不通 ?然后,尝试以下操作:
Login with SYSTEM
user and register LOCAL_LISTENER
by running below SQLs.
使用SYSTEM
用户登录并LOCAL_LISTENER
通过运行下面的 SQL 进行注册。
alter system set local_listener = '(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' scope = both;
alter system register;
How to check oracle SID and service name :
如何检查 oracle SID 和服务名称:
SELECT sys_context('USERENV', 'SID') FROM DUAL; -- It will return your oracle database SID
SELECT sys_context('USERENV', 'SERVICE_NAME') FROM DUAL; -- It will return your oracle database service name
回答by Jean de Lavarene
If you want to know the default SID of your database use this query in sqlplus:
如果您想知道数据库的默认 SID,请在 sqlplus 中使用此查询:
SELECT sys_context('USERENV', 'SID') FROM DUAL;
Use this value in the JDBC URL instead of "orcl".
在 JDBC URL 中使用此值而不是“orcl”。
回答by Nirmala
Can you use the below URL?
Note the difference, this is to use the SERVICENAME instead of a SID.
您可以使用以下网址吗?
请注意区别,这是使用 SERVICENAME 而不是 SID。
jdbc:oracle:thin:@localhost:1521/orclservice
回答by RajaRamakhil
I am facing the same problem.
我面临同样的问题。
Try removing the LAN cable or disconnect your net connectivity and restart the services of Listener and run the code.
尝试移除 LAN 电缆或断开网络连接并重新启动 Listener 服务并运行代码。
It worked for me.
它对我有用。