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());
}
}