这是我的程序:import java.sql.*;public class TestJDBC { public static void main(String[] args) {
Connection conn = null;
Statement statm = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
try {
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "scott", "tiger");
statm = conn.createStatement();
rs = statm.executeQuery("select * from dept");
while (rs.next()) {
System.out.println(rs.getString("deptno"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (statm != null) {
statm.close();
statm = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}总是报如下错误:
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:
127.0.0.1:1521:ORCL我检查了我的服务和监听都启动了,classes12.jar也引入了:为什么还抱着这样错?请大家帮帮忙, 万分感谢!!!!
Connection conn = null;
Statement statm = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
try {
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "scott", "tiger");
statm = conn.createStatement();
rs = statm.executeQuery("select * from dept");
while (rs.next()) {
System.out.println(rs.getString("deptno"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (statm != null) {
statm.close();
statm = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}总是报如下错误:
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:
127.0.0.1:1521:ORCL我检查了我的服务和监听都启动了,classes12.jar也引入了:为什么还抱着这样错?请大家帮帮忙, 万分感谢!!!!
listener does not currently know of SID given in connect descriptor
SID不认识,确认一下你的数据库SID