Listener refused the connection with the following error: ORA-12505, TNS: listener does not currently, ora12505
When you connect to oacle12c using java, an error is returned:
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
At oracle. jdbc. driver. T4CConnection. logon (T4CConnection. java: 673)
At oracle. jdbc. driver. PhysicalConnection. <init> (PhysicalConnection. java: 711)
At oracle. jdbc. driver. T4CConnection. <init> (T4CConnection. java: 385)
At oracle. jdbc. driver. T4CDriverExtension. getConnection (T4CDriverExtension. java: 30)
At oracle. jdbc. driver. OracleDriver. connect (OracleDriver. java: 558)
At java. SQL. DriverManager. getConnection (DriverManager. java: 664)
At java. SQL. DriverManager. getConnection (DriverManager. java: 247)
At demo1.DBHelp. getCon (DBHelp. java: 16)
At demo1.DBHelp. main (DBHelp. java: 28)
Caused by: oracle.net. ns. NetException: Listener refused the connection with the following error:
ORA-12505, TNS: listener does not currently know of SID given in connect descriptor
At oracle.net. ns. NSProtocolStream. negotiateConnection (NSProtocolStream. java: 272)
At oracle.net. ns. NSProtocol. connect (NSProtocol. java: 263)
At oracle. jdbc. driver. T4CConnection. connect (T4CConnection. java: 1360)
At oracle. jdbc. driver. T4CConnection. logon (T4CConnection. java: 486)
... 8 more
Obviously, this is because the listener cannot identify the database SID in the connection identifier. I checked it online.
The solution on the internet is as follows: Find tnsnames. use notepad or other tools to open the ora file. Note that I am the path of the oracle12c file. Different oracle versions are in different paths.
D: \ oracle \ app \ Administrator \ product \ 12.1.0 \ dbhome_1 \ NETWORK \ ADMIN tnsnames. ora
The file content is as follows:
# Tnsnames. ora Network Configuration File: D: \ oracle \ app \ Administrator \ product \ 12.1.0 \ dbhome_1 \ network \ admin \ tnsnames. ora
# Generated by Oracle configuration tools.
LISTENER_TEST =
(ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT = 1521 ))
LISTENER_ORACLE12C =
(ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT = 1521 ))
Export lr_connection_data =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC1521 ))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
ORACLE12C =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT = 1521 ))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oracle12c)
)
)
// Change the original red part to the content shown above. The green part is the Instance name of the database when you installed it,
D: \ oracle \ app \ Administrator \ product \ 12.1.0 \ dbhome_1 \ NETWORK \ ADMIN listener. ora File
The file content is as follows:
# Listener. ora Network Configuration File: D: \ oracle \ app \ Administrator \ product \ 12.1.0 \ dbhome_1 \ network \ admin \ listener. ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D: \ oracle \ app \ Administrator \ product \ 12.1.0 \ dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS = ONLY: D: \ oracle \ app \ Administrator \ product \ 12.1.0 \ dbhome_1 \ bin \ lrlr12.dll ")
)
(SID_DESC =
(GLOBAL_DBNAME = oracle12c)
(ORACLE_HOME = D:\oracle\app\Administrator\product\12.1.0\dbhome_1)
(SID_NAME = oracle12c)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT = 1521 ))
(ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC1521 ))
)
)
The red part is added, saved, and restarted the oracle service.
The test content is as follows:
Package demo1;
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. ResultSet;
Import java. SQL. SQLException;
Import java. SQL. Statement;
Public class DBHelp {
Private static String URL = "jdbc: oracle: thin: @ 127.0.0.1: 1521: oracle12 ";
Private static String USERNAME = "system ";
Private static String PASSWORD = "940109 ";
Public static Connection getCon (){
Connection conn = null;
Try {
Class. forName ("oracle. jdbc. driver. OracleDriver ");
Conn = DriverManager. getConnection (URL, USERNAME, PASSWORD );
If (conn! = Null)
System. out. println ("connect successful ");
} Catch (Exception e ){
E. printStackTrace ();
}
Return conn;
}
/**
* @ Param args
*/
Public static void main (String [] args ){
System. out. println (new DBHelp (). getCon ());
}
Public static void close (Connection con, Statement sm, ResultSet rs ){
Try {
If (con! = Null ){
Con. close ();
}
If (sm! = Null ){
Sm. close ();
}
If (rs! = Null ){
Rs. close ();
}
} Catch (SQLException e ){
E. printStackTrace ();
}
}
}
// No error will be reported.
Connect successful
Oracle. jdbc. driver. T4CConnection @ 1edf1c96
That is, the name of the instance was changed when oracle12c was installed. If it is installed according to the default instance, the above content basically does not need to be modified.
It is not installed according to the default instance.