0

My code is as below.

java.sql.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
java.sql.Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "ims", "_ims");

The exception occurs at second line which is given below.

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:
localhost:1521:xe"

What does exception means? Whats wrong in my code?

Edit by Girish

the listener.ora file :

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
      (ADDRESS = (PROTOCOL = TCP)(HOST = Girish-PC)(PORT = 1521))
    )
  )

DEFAULT_SERVICE_LISTENER = (XE)

The tnsnames.ora file :

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = Girish-PC)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

ORACLR_CONNECTION_DATA = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE)) 
    ) 
    (CONNECT_DATA = 
      (SID = CLRExtProc) 
      (PRESENTATION = RO) 
    ) 
  ) 

In above, both tnsnames.ora and listener.ora file's contents is given.

3
  • is listener.ora file available under oracle\admin\network. If available check the port and service. Commented Jul 17, 2015 at 7:21
  • yes, both files available, and also entries in that file are available. Commented Jul 17, 2015 at 7:34
  • @Girish try your system IP in place of localhost. Commented Jul 17, 2015 at 10:51

3 Answers 3

2

I've replaced my oracle**.jar with new one, n its work. I think there was problem with my old oracle**.jar. Thanks to everyone for support.

Sign up to request clarification or add additional context in comments.

Comments

1

It means given sid(xe) is not available.

Listener is not able to recognise or find it in listener.ora or tnsnames.ora file.Please check the files and verify whether entry for the xe sid is present or not.

If entry is present in the above files then check listener is running or not.

** Updated**

Use below jdbc url

jdbc:oracle:thin:@myserver:1521/XE

7 Comments

both (as you said) .ora files are available, also oracle's services are running.
entries for the xe sid are present in those files?, can u please post the contents here...
Entries available in both files.
Exception : java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
|
1

your are using sting like

jdbc:oracle:thin:@myserver:1521:XE

try like

jdbc:oracle:thin:@myserver:1521/XE

Because I'm already faced same issue. with this I resolved it.

Make sure that OracleServiceXE, OracleXETNSListener is running.

Still facing issue

5 Comments

I've did as per your suggestion, but the following exception occured : java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
so check username and password whether you enter correct or not. Also may network setup. Make sure that OracleServiceXE, OracleXETNSListener is running.
Also OracleServiceXE and OracleXETNSListener is running.
I've tested as per your updated answer and comment. But not working. Now I'm asking silly question, is there any problem with oracle 10g setup I have?
who exactly knows that. since it was install in your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.