oracle连接池错误求解决
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
连接代码
package dbutil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBConnection {
private static final String CLASSDRIVER="oracle.jdbc.driver.OracleDriver";
private static final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
private static final String USERNAME="scott";
private static final String PASSWORD="root";
static{
try {
Class.forName(CLASSDRIVER);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConn(){
Connection conn = null;
try {
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static void close(ResultSet rs,Statement stat,Connection conn){
try {
if(rs != null){
rs.close();
}
if(stat != null){
stat.close();
}
if(conn != null){
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println(getConn());
}
}
------解决方案--------------------你的数据库SID是orcl?
------解决方案--------------------是orcl
------解决方案--------------------在别个电脑上这代码可以运行,没错,但我自己电脑会出错,怎么解决啊
------解决方案--------------------用CMD窗口
输入tnsping orcl是否ping通