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.

Girish
  • 213
  • 2
  • 13

3 Answers3

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.

Girish
  • 213
  • 2
  • 13
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

Anjali
  • 1,623
  • 5
  • 30
  • 50
  • both (as you said) .ora files are available, also oracle's services are running. – Girish Jul 17 '15 at 07:13
  • entries for the xe sid are present in those files?, can u please post the contents here... – Anjali Jul 17 '15 at 07:14
  • Entries available in both files. – Girish Jul 17 '15 at 07:18
  • Exception : `java.sql.SQLException: Io exception: The Network Adapter could not establish the connection` – Girish Jul 17 '15 at 07:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83509/discussion-between-anjali-and-girish). – Anjali Jul 17 '15 at 07:33
  • try this ..http://stackoverflow.com/questions/5661610/tns-12505-tnslistener-does-not-currently-know-of-sid-given-in-connect-descript – Anjali Jul 17 '15 at 07:46
  • this one also...http://stackoverflow.com/questions/18192521/ora-12505-tnslistener-does-not-currently-know-of-sid-given-in-connect-descript – Anjali Jul 17 '15 at 07:47
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

Community
  • 1
  • 1
SatyaTNV
  • 4,137
  • 3
  • 15
  • 31
  • 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` – Girish Jul 17 '15 at 07:01
  • so check username and password whether you enter correct or not. Also may network setup. Make sure that `OracleServiceXE`, `OracleXETNSListener` is running. – SatyaTNV Jul 17 '15 at 07:03
  • Also OracleServiceXE and OracleXETNSListener is running. – Girish Jul 17 '15 at 07:11
  • 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? – Girish Jul 17 '15 at 07:59
  • who exactly knows that. since it was install in your system. – SatyaTNV Jul 17 '15 at 08:32