File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes java.sql.SQLException: Io exception: The Network Adapter could not establish the conn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: Io exception: The Network Adapter could not establish the conn" Watch "java.sql.SQLException: Io exception: The Network Adapter could not establish the conn" New topic
Author

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

sarma kiran
Ranch Hand

Joined: Jul 17, 2008
Posts: 30
Hi,
I am trying to use oracle from my jave program, i got following exception
Exception in thread "main" java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at JdbcTest.main(JdbcTest.java:26)

I have searched through net, but i can't find the solution. I am struggling with this problem from past 4 days.I am using Windows vista o.s and oracle 10g datavbase.

Here is the jdbc code,
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbcracle:thin:@127.0.0.1:1521:XE","system", "manager");
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Can you connect to the database outside of JDBC via a general client such as Toad? I'd download such a tool and confirm the database is reachable there before pulling your hair out in JDBC.


My Blog: Down Home Country Coding with Scott Selikoff
vij reddy
Greenhorn

Joined: Jul 20, 2008
Posts: 3
I am also facing same problem while I was trying to connect to Database. My database is Oracle 10g XE and my OS is Win XP sp2.
I could connect to the database by using SQL command prompt.
bell saleem
Greenhorn

Joined: Jul 20, 2008
Posts: 9
run the command 'telnet localhost 1521' on the command prompt where the database is running.
As you have said it is windows vista, 'telnet' may not work by default enable it by going to control panel and 'programs and features'.

if 'telnet localhost 1521' works then it is sure that your program should work.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It's probably easier than that...
Notice that the URL says to connect to "127.0.0.1". That's the same computer where the code is running. It should be straightforward to ask yourself "Am I running an Oracle database instance on my computer?"
vij reddy
Greenhorn

Joined: Jul 20, 2008
Posts: 3
It is not working even I use 127.0.0.1 in place of local host
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

I could connect to the database by using SQL command prompt.
How do you connect using the SQL command prompt?
Are you using SQL*Plus? What parameters do you use when you start it?

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
vij reddy
Greenhorn

Joined: Jul 20, 2008
Posts: 3
I connected by using SQL*Plus

connect system/oracle

and then I could execute the following querries

create table ...
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

You start sql*plus without telling it the database to connect to.
This means you are connecting to the default Oracle database on your computer.

Try to get the connection settings for this default database. Use them to configure your connection url.

from Starting SQL*Plus:
The default database is configured at an operating system level by setting operating system environment variables, symbols or, possibly, by editing an Oracle specific configuration file. Refer to the Oracle documentation for your operating system for more information.
sarma kiran
Ranch Hand

Joined: Jul 17, 2008
Posts: 30
I am able to connect to SQL* plus. I am able to work with database.
when i check the listener status. I am able to see the same service_name, host and port number, which i am using in the code.
sarma kiran
Ranch Hand

Joined: Jul 17, 2008
Posts: 30
I am able to connect to SQL * Plus..

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jul 29 08:51:27 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn system
Enter password:
Connected.
SQL> select instance_name from V$instance;
INSTANCE_NAME
----------------
xe
SQL>

Here is the listener status and services


C:\>lsnrctl services

LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 29-JUL-2008 08:46:43
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "XEXDB" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1002 state:ready
DISPATCHER <machine: KIRANKUMAR-PC, pid: 3632>
(ADDRESS=(PROTOCOL=tcp)(HOST=KiranKumar-PC)(PORT=49160))
Service "XE_XPT" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "xe" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully


C:\>lsnrctl status

LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 29-JUL-2008 08:46:56
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Production
Start Date 29-JUL-2008 08:39:27
Uptime 0 days 0 hr. 7 min. 29 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File C:\oraclexe\app\oracle\product\10.2.0\server\network\admin\listener.ora
Listener Log File C:\oraclexe\app\oracle\product\10.2.0\server\network\log\listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=KiranKumar-PC)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=KiranKumar-PC)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "XEXDB" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Service "XE_XPT" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Service "xe" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
The command completed successfully

C:\>TNSPING xe
TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 29-JUL-2008 08:49:28
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
C:\oraclexe\app\oracle\product\10.2.0\server\network\admin\sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = KiranKumar-PC)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))
OK (250 msec)


C:\>tnsping kirankumar-pc
TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 29-JUL-2008 08:49:42
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
C:\oraclexe\app\oracle\product\10.2.0\server\network\admin\sqlnet.ora
Used HOSTNAME adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))
OK (170 msec)


Please check this... Let me know the solution..
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128

check the following

[*]1. password : From the chain above it looks like you are using "oracle" as the password for connecting through SQL Plus and "manager" through java.

[*]2. use localhost instead of the loop back ip address and see the difference.

Well if wont hurt trying it.
sarma kiran
Ranch Hand

Joined: Jul 17, 2008
Posts: 30
In the Sql * plus i am using the password as"manager" to login.
I have tested the program by giving "localhost","127.0.0.1" as host name .
But still i have same problem.
danthuluri pavan kumar
Greenhorn

Joined: Sep 25, 2008
Posts: 3
i AM ALSO HAVING THE SAME PROBLEM.EVERTHING IS IN PLACE

1.db is up and running

2.db listener is also running

Able login to oracle db using sql command prompt,but not through JDBC.I am getting the error

java.sql.SQLException: Io exception: The Network Adapter could not establish the conn
[ September 25, 2008: Message edited by: danthuluri pavan kumar ]
sarma kiran
Ranch Hand

Joined: Jul 17, 2008
Posts: 30
Which os your are using. If you are using windowsXP then install oracle 10g Enterprise edition. Then this problem will solve.
Kusal Gautamadasa
Greenhorn

Joined: Oct 01, 2008
Posts: 3
There a few reason that you getting this error message:

>Perhaps TNS Lister instance is down in the DB server
>privileges are not granted for your credentials or the
>1521 port is not visible/available to you


What you can do is restart the DB instance and the listeners and check the status of the instances.
David Boyd
Greenhorn

Joined: Apr 20, 2004
Posts: 1
I ran into this same issue. Turned out that my host name was not correct in the listener.ora and tnsnames.ora files. Once I made the changes, life was good
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1131

Sarma,
This may be of help:

http://forums.oracle.com/forums/thread.jspa?messageID=2025226

Good Luck,
Avi.
Rajeev roushan sharma
Ranch Hand

Joined: Jan 28, 2010
Posts: 50
Hi, if you get the solution, could you please share.
Thanks



sarma kiran wrote:I am able to connect to SQL * Plus..

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jul 29 08:51:27 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn system
Enter password:
Connected.
SQL> select instance_name from V$instance;
INSTANCE_NAME
----------------
xe
SQL>

Here is the listener status and services


C:\>lsnrctl services

LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 29-JUL-2008 08:46:43
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "XEXDB" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1002 state:ready
DISPATCHER <machine: KIRANKUMAR-PC, pid: 3632>
(ADDRESS=(PROTOCOL=tcp)(HOST=KiranKumar-PC)(PORT=49160))
Service "XE_XPT" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "xe" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully


C:\>lsnrctl status

LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 29-JUL-2008 08:46:56
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Production
Start Date 29-JUL-2008 08:39:27
Uptime 0 days 0 hr. 7 min. 29 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File C:\oraclexe\app\oracle\product\10.2.0\server\network\admin\listener.ora
Listener Log File C:\oraclexe\app\oracle\product\10.2.0\server\network\log\listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=KiranKumar-PC)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=KiranKumar-PC)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "XEXDB" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Service "XE_XPT" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Service "xe" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
The command completed successfully

C:\>TNSPING xe
TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 29-JUL-2008 08:49:28
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
C:\oraclexe\app\oracle\product\10.2.0\server\network\admin\sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = KiranKumar-PC)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))
OK (250 msec)


C:\>tnsping kirankumar-pc
TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 29-JUL-2008 08:49:42
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
C:\oraclexe\app\oracle\product\10.2.0\server\network\admin\sqlnet.ora
Used HOSTNAME adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))
OK (170 msec)


Please check this... Let me know the solution..
prathamesh bandivadekar
Ranch Hand

Joined: May 22, 2008
Posts: 43
Hey Hi,

I got connected to Oracle server using following setup

String jdbcurl = "jdbcracle:thin:@<machine IP>:1521:<DB Name>";

Class c= Class.forName("oracle.jdbc.driver.OracleDriver");

Driver d = (Driver) c.newInstance();

Properties p = new Properties();
p.put("user", "demo");
p.put("password", "demo");

con = d.connect(jdbcurl,p);

Here DBname is one i created in Oracle and its realtime user and pwd is demo/demo itself.

Hope this helps!


Prathamesh M.B.<br />Java....only.....
Donald garfed
Greenhorn

Joined: Jun 19, 2011
Posts: 1
I tried to connect to the database. My database is Oracle 10g, XE and my OS is Win XP SP2. I can connect to the database using SQL command prompt....


There are various shapes of White leather shoulder bags these days starting from modest to huge. Yet another well-known option is a Orange leather shoulder bag.
venkat penmatsa
Greenhorn

Joined: Jul 23, 2011
Posts: 17
bell saleem wrote:run the command 'telnet localhost 1521' on the command prompt where the database is running.
As you have said it is windows vista, 'telnet' may not work by default enable it by going to control panel and 'programs and features'.

if 'telnet localhost 1521' works then it is sure that your program should work.



Hi

I am also getting the same issue i checked 'telnet localhost 1521' its connecting i am attaching my code please tell
where i am getting the error and also i am using ojdbc driver

import java.sql.*;

public class Diff {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {

String usr = "scott@orcl";
String pwd = "tiger";
String url = "jdbcracle:thin:@localhost:1521/test";
Connection con=null;
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con=DriverManager.getConnection(url, usr, pwd);
System.out.println("connected");
}

}
 
 
subject: java.sql.SQLException: Io exception: The Network Adapter could not establish the conn