Exception in thread "main" 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: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:414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oraenter code herecle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.test.Date.main(Date.java:13)
这是我的代码
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger");
我还验证了tnsnames.ora
文件
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = orcl)
)
)
我在类路径中添加了ojdbc14.jar
,我正在使用oracle10g
请你帮我解决一下。
答案 0 :(得分:1)
如上所述,请检查您是否能够执行tnsping
tnsping orcl
,如果工作正常,请尝试从sqlplus或TOAD
或{{1}等任何工具连接到您的数据库}}。如果您收到任何错误,请发布错误,否则请使用以下内容连接到您的数据库并查看其工作原理。
SQLDeveloper
<强> try {
Class.forName("oracle.jdbc.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
return;
}
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger");
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
close(connection);
}
return
强>
您可以尝试使用以下代码
Update 1
如果不起作用,请尝试以下
jdbc:oracle:thin:@//localhost:1521:orcl","system","tiger
更多信息here
此致