简体   繁体   中英

Exception occured when connecting java to oracle 10g

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM