在尝试使用 java 8 中的 jdbc 连接到 oracle 18c 时,使用
"Class.forName("oracle.jdbc.driver.OracleDriver"); cn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","PL","PL"); "
我收到 2 个异常“原因:oracle.net.ns.NetException:侦听器拒绝连接并出现以下错误:ORA-12505,TNS:侦听器当前不知道连接描述符中给出的 SID”“java.sql.SQLException:侦听器拒绝连接并出现以下错误:ORA-12505,TNS:侦听器当前不知道连接描述符中给出的 SID”
我尝试在 CMD 中执行“lsnrctl status”和“lsnrctl services”并且还检查了“D:\db_home\dbhomeXE\network\admin\tnsnames.ora”文件和“D:\db_home\dbhomeXE\network\admin\listener.ora” "
tnsnames.ora
# tnsnames.ora Network Configuration File: D:\db_home\dbhomeXE\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
LISTENER_XE =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
监听器.ora
# listener.ora Network Configuration File: D:\db_home\dbhomeXE\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
DEFAULT_SERVICE_LISTENER = XE
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\db_home\dbhomeXE)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:D:\db_home\dbhomeXE\bin\oraclr18.dll")
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
lsnrctl 服务的o/p:
Copyright (c) 1991, 2018, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
The command completed successfully```
o/p of lsnrctl status:
```LSNRCTL for 64-bit Windows: Version 18.0.0.0.0 - Production on 12-SEP-2019 01:34:23
Copyright (c) 1991, 2018, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 64-bit Windows: Version 18.0.0.0.0 - Production
Start Date 11-SEP-2019 20:13:48
Uptime 0 days 5 hr. 20 min. 39 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File D:\db_home\dbhomeXE\network\admin\listener.ora
Listener Log File D:\db_home\diag\tnslsnr\DESKTOP-ARH7AVT\listener\alert\log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DESKTOP-ARH7AVT)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully```
I'm getting
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
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