Please go through the JAVA code below:
-
class Main{
-
public Connection getConnection(){
-
Connection l_con = null;
-
try {
-
String hostname = "172.10.23.1:1527"; //Host IP:port No
-
String dbsid = "TESTSID"; //SID Name or Service Name
-
String username = "TESTUSER"; //Database user
-
String password = "password"; //User password
-
String connectingString = "jdbc:oracle:thin:@" + hostname + ":" + dbsid;
-
-
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
-
l_con = DriverManager.getConnection(connectingString,username,password);
-
-
} catch (SQLException ex) {
-
Logger.getLogger(SQLUtil.class.getName()).log(Level.SEVERE, null, ex);
-
}
-
return l_con;
-
}
-
-
-
public static void main(String s[]){
-
Main main= new Main();
-
Connection l_con = sqlutil.getConnection();
-
}
-
-
}
-
-
When I run the following code we found some error like that:
<ERROR>
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:
172.10.23.1:1527:TESTSID
</ERROR>
Please give me the solution. Thank you.