我的代码如下。
java.sql.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
java.sql.Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "ims", "_ims");
异常发生在第二行,如下所示。
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
The Connection descriptor used by the client was:
localhost:1521:xe"
异常是什么意思?我的代码有什么问题?
Girish编辑
listener.ora文件:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(ADDRESS = (PROTOCOL = TCP)(HOST = Girish-PC)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = (XE)
tnsnames.ora文件:
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Girish-PC)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
在上面,给出了tnsnames.ora和listener.ora文件的内容。
答案 0 :(得分:2)
我已经用新工具取代了我的oracle **。jar。我觉得我的旧oracle **罐子有问题。感谢大家的支持。
答案 1 :(得分:1)
这意味着给定的sid(xe)不可用。
侦听器无法在listener.ora或tnsnames.ora文件中识别或找到它。请检查文件并验证是否存在xe sid的条目。
如果上述文件中存在条目,则检查侦听器是否正在运行。
**更新**
使用以下jdbc url
JDBC:预言:瘦:@myserver:1521 / XE
答案 2 :(得分:1)
你正在使用像
这样的刺痛jdbc:oracle:thin:@myserver:1521:XE
尝试
jdbc:oracle:thin:@myserver:1521/XE
因为我已经面临同样的问题。有了这个,我解决了它。
确保OracleServiceXE
,OracleXETNSListener
正在运行。