jdbc connection error with oracle

2.8k Views Asked by At

I am unable to connect to oracle database using jdbc.

Error: Could not connect to database at jdbc:oracle:thin:@localhost.localdomain:1521:orcl (Username: system, Password: tiger)

However, I can connect it using sqlplus command.

Here is the log:

java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
Version = Sun GlassFish Enterprise Server v2.1
Testing Database Connection ...
  -- Failure! java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

Here is the listener.ora:

 LISTENER =
 (DESCRIPTION_LIST =
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
   (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = /home/oracle/app/oracle

Output of lsnrctl:

Listening Endpoints Summary...
 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=::1)(PORT=1521)))
 Services Summary...
 Service "orcl" has 1 instance(s).
 Instance "orcl", status READY, has 1 handler(s) for this service...
 Service "orclXDB" has 1 instance(s).
 Instance "orcl", status READY, has 1 handler(s) for this service...
 The command completed successfully

Contents of tnsnames.ora:

 ORCL =
   (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

I am using Oracle 11g, glassfish server 2.1, Redhat linux enterprise edition 6.

Any help would be really appreciated.

--Sam

2

There are 2 best solutions below

0
On

Try replacing localhost.localdomain with localhost in the connection string, i.e.

jdbc:oracle:thin:@localhost:1521:orcl

I too get a The Network Adapter could not establish the connection error if I use localhost.localdomain as the address, and it goes away if I use just localhost.

0
On

Test :

 telnet localhost 1521

and if it does not work

Set iptables :

https://exploringspatial.wordpress.com/2013/06/08/installing-oracle-sql-developer/