• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to establish a network connection

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been struggling all day to make a JDBC connection to my Oracle database. Here is the connection code I have:



The error I get when I run this code is this:

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

I've done extensive Googling on this, and people have suggested that if I am able to run the following telnet command from my command prompt then JDBC should work:

telnet localhost 1521

When I run that command, I get an error, so I think this is the heart of my problem (though I don't really understand it). This is the error message:

Could not open connection to the host, on port 1521: Connect failed

I've also seen online that I need to make sure that a listener is working, using the lsnrctl command. I believe that it is started. When I enter "status" in the lsnrctl prompt, I get this:

Connecting to <DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
-------------------------------
Alias LISTENER
Version TNSLSNR for 32-bit Windows: Version 10.2.0.3.0 - Production
Start Date 01-APR-2011 22:21:20
Uptime 0 days 0 hr. 0 min. 28 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File C:\oracle\product\10.2.0\db_1\network\admin\listener.ora
Listener Log File C:\oracle\product\10.2.0\db_1\network\log\listener.log

Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(HOST=10.0.1.5)(PORT=1521)))
Services Summary...
Service "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully


Please help. I am desperate to fix this issue but have not been able to figure out how to resolve my telnet problem all day long.
 
Jack Bernstein
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I believe I got telnet localhost 1521 to work. Now when I run my JDBC code I get this error:

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:jackdb

To try to determine my SID, I enter the SELECT INSTANCE FROM v$thread; in my command prompt and I get jackdb as my response. If I enter SELECT NAME FROM v$database; I get JACKDB.

I have tried using both localhost:1521:jackdb and localhost:1521:JACKDB as my connection descriptor in my JDBC code, but still get the same exception and message. Any ideas what might be going wrong?
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jack,

As far as I understood you have one Oracle database instance running on your localhost residing on port 1521. So far so good, but from your connection string it seems to be "db_1" is the SID of your database. Is this correct? Can you verify this? Can you connect to your database with some sql tool like Toad, Sql Developer or sqlplus? You may try sqlplus "/as sysdba" from command line if you know OS Admin user.

If you can connect to db with some other tool, what does this query returns?


If you can not connect -but really you should with sqlplus- check this file "C:\oracle\product\10.2.0\db_1\network\admin\tnsnames.ora". What is the SID or Service Name?

Regards,
Fatih.
 
Jack Bernstein
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fatih,

Thank you for the reply! Yes, I am able to connect using sqlplus. As you can see in my comment above, when I type I get JACKDB. It is not actually db_1 like I thought in my original post. I have tried using localhost:1521:JACKDB as my connection descriptor in the JDBC code, but it is giving me this exception:

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:jackdb

Any ideas?
 
Fatih Keles
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try jdbc:oracle:thin:@localhost:1521:JACKDB as connection string?
 
Jack Bernstein
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I've tried both

jdbc:oracle:thin:@127.0.0.1:1521:jackdb

and

jdbc:oracle:thin:@127.0.0.1:1521:JACKDB

as my connection strings. Both yield that same SQLException.
 
Fatih Keles
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be able to connect via telnet on service port as you did (telnet localhost 1521). There may a problem with the listener service. Can you restart the listener service, share listener.ora file with us? I doubt if the service is running.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic