Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Oracle JDBC Problem

5 views
Skip to first unread message

jct...@nb.sympatico.ca

unread,
Sep 4, 2006, 10:20:04 AM9/4/06
to
I have a Java program on a laptop which is trying to access an Oracle
XE Database on my desktop.


Here is the error I get...obviously there is something wrong with a
connection string or something but I don't know what it would be


Exception in thread "main" java.sql.SQLException: Io exception: The
Network Adapter could not establish the connection
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:254)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:386)
at
oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:419)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)
at
oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Oracle.OracleTest.main(OracleTest.java:12)

And here is my source

package Oracle;

import java.lang.*;
import java.util.*;
import java.sql.*;

class OracleTest {
public static void main (String args []) throws SQLException
{
DriverManager.registerDriver (new
oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@emily5:1521:XE", "xxxxxx", "######"");
// @machineName:port:SID, userid,
password

Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from books");
while (rset.next())
{
int index = 1;
while (index <= 7)
{
System.out.print (rset.getString(index) + " ");
index++;
}
System.out.println ("");
}
stmt.close();

}
}

The program compiles and I have the odbc jar on the class path.

Rohit Kumbhar

unread,
Sep 4, 2006, 2:01:27 PM9/4/06
to
jct...@nb.sympatico.ca wrote:
> [...]

>
> Exception in thread "main" java.sql.SQLException: Io exception: The
> Network Adapter could not establish the connection

Can you ping your desktop machine from your laptop?

jct...@nb.sympatico.ca

unread,
Sep 4, 2006, 3:01:53 PM9/4/06
to

yup... using both alias and ip

Juha Laiho

unread,
Sep 4, 2006, 3:07:04 PM9/4/06
to
"jct...@nb.sympatico.ca" <jct...@nb.sympatico.ca> said:
>I have a Java program on a laptop which is trying to access an Oracle
>XE Database on my desktop.
...

>Exception in thread "main" java.sql.SQLException: Io exception: The
>Network Adapter could not establish the connection
> at
>oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
...
> at Oracle.OracleTest.main(OracleTest.java:12)

Ok, the error tells a number of things:
- you got the proper drivers loaded (Oracle JDBC, not ODBC)
- the database JDBC URL is at least correct enough that the
driver attempted to connect
- the connection attempt failed

>package Oracle;
>
>import java.lang.*;
>import java.util.*;
>import java.sql.*;
>
>class OracleTest {
> public static void main (String args []) throws SQLException
> {
> DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
>
> Connection conn = DriverManager.getConnection
> ("jdbc:oracle:thin:@emily5:1521:XE", "xxxxxx", "######"");

So, it fails here. Looking ad the JDBC URL, it seems correct, assuming that
"emily5" is the name (in TCP/IP DNS, not just an arbitary computer name)
of the desktop running the database. As someone else responded, try pinging
that name, to see if it responds.

Other things, are you running Oracle TNS Listener service on emily5?
Is the listener service listening on port 1521?

You could find out these with commands
lsnrctl status
netstat -a
on the database server machine.

> int index = 1;
> while (index <= 7)
> {
> System.out.print (rset.getString(index) + " ");
> index++;
> }

As an aside, this could be more naturally written as a for loop:
for (int index = 1; index <= 7; index++) {
System.out.print(rset.getString(index) + " ");
}

> System.out.println ("");
> }
> stmt.close();

... and in real programs, remember to also close the connection:

conn.close();

--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)

Daniel Dyer

unread,
Sep 4, 2006, 3:38:24 PM9/4/06
to
On Mon, 04 Sep 2006 15:20:04 +0100, jct...@nb.sympatico.ca
<jct...@nb.sympatico.ca> wrote:

> I have a Java program on a laptop which is trying to access an Oracle
> XE Database on my desktop.
>
>
> Here is the error I get...obviously there is something wrong with a
> connection string or something but I don't know what it would be

...

> Connection conn = DriverManager.getConnection
> ("jdbc:oracle:thin:@emily5:1521:XE", "xxxxxx", "######"");
> // @machineName:port:SID, userid,
> password

My (working) Oracle JDBC URLs have the SID separated from the port with a
forward slash, like this:

jdbc:oracle:thin:@emily5:1521/XE

Dan.

--
Daniel Dyer
http://www.dandyer.co.uk

jct...@nb.sympatico.ca

unread,
Sep 4, 2006, 4:15:54 PM9/4/06
to

Juha Laiho wrote:
> "jct...@nb.sympatico.ca" <jct...@nb.sympatico.ca> said:
> >I have a Java program on a laptop which is trying to access an Oracle
> >XE Database on my desktop.
> ...
> >Exception in thread "main" java.sql.SQLException: Io exception: The
> >Network Adapter could not establish the connection
> > at
> >oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
> ...
> > at Oracle.OracleTest.main(OracleTest.java:12)
>
> Ok, the error tells a number of things:
> - you got the proper drivers loaded (Oracle JDBC, not ODBC)
> - the database JDBC URL is at least correct enough that the
> driver attempted to connect
> - the connection attempt failed
>
> So, it fails here. Looking ad the JDBC URL, it seems correct, assuming that
> "emily5" is the name (in TCP/IP DNS, not just an arbitary computer name)
> of the desktop running the database. As someone else responded, try pinging
> that name, to see if it responds.

No problem here:

F:\>ping emily5

Pinging emily5 [192.168.0.100] with 32 bytes of data:

Reply from 192.168.0.100: bytes=32 time=1ms TTL=128
Reply from 192.168.0.100: bytes=32 time=1ms TTL=128
Reply from 192.168.0.100: bytes=32 time=1ms TTL=128
Reply from 192.168.0.100: bytes=32 time=1ms TTL=128

Ping statistics for 192.168.0.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 1ms, Average = 1ms


>
> Other things, are you running Oracle TNS Listener service on emily5?
> Is the listener service listening on port 1521?
>
> You could find out these with commands
> lsnrctl status
> netstat -a
> on the database server machine.
>

Here are the results of the execution of the above two commands on the
database server machine.


J:\> lsnrctl status

LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on
04-SEP-2006 17:11
:27

Copyright (c) 1991, 2005, Oracle. All rights reserved.

Connecting to
(DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 32-bit Windows: Version
10.2.0.1.0 - Produ
ction
Start Date 01-SEP-2006 18:52:11
Uptime 2 days 22 hr. 19 min. 15 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\a
dmin\listener.ora
Listener Log File
C:\oraclexe\app\oracle\product\10.2.0\server\network\l
og\listener.log
Listening Endpoints Summary...

(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC_FOR_XEipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Emily5)(PORT=1521)))

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Emily5)(PORT=8081))(Presentation=HTT
P)(Session=RAW))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this
service...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this
service...
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

J:\>


J:\> netstat -a

Active Connections (only 1521 is displayed to save bandwidth)

Proto Local Address Foreign Address State

TCP Emily5:1521 Emily5:0 LISTENING
---------------------------------------------------------------------
It looks like everything is fine on both sides so that's why I asked
the original question.
I suspect it has something to do with the tns names file which I dont
have on the remote box,

jct...@nb.sympatico.ca

unread,
Sep 4, 2006, 4:23:58 PM9/4/06
to

Hi, I changed the separator but got the same error


Exception in thread "main" java.sql.SQLException: Io exception: The
Network Adapter could not establish the connection
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:254)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:386)
at
oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:419)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)

I'm using Eclipse 3.2

Greg R. Broderick

unread,
Sep 4, 2006, 9:05:55 PM9/4/06
to
Juha Laiho <Juha....@iki.fi> wrote in news:edht9d$ghq$2...@ichaos2.ichaos-int:

>> System.out.println ("");
>> }
>> stmt.close();
>
> ... and in real programs, remember to also close the connection:
>
> conn.close();
>

Preferrably in a finally clause, so that it is executed even if the code
throws an exception!

Cheers
GRB


--
---------------------------------------------------------------------
Greg R. Broderick gregb.use...@blackholio.dyndns.org

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------

Juha Laiho

unread,
Sep 5, 2006, 1:52:04 PM9/5/06
to
"jct...@nb.sympatico.ca" <jct...@nb.sympatico.ca> said:
>Juha Laiho wrote:
>> "jct...@nb.sympatico.ca" <jct...@nb.sympatico.ca> said:
>> >I have a Java program on a laptop which is trying to access an Oracle
>> >XE Database on my desktop.
>> ...
>> >Exception in thread "main" java.sql.SQLException: Io exception: The
>> >Network Adapter could not establish the connection
>> > at
>> >oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
>> ...
>> > at Oracle.OracleTest.main(OracleTest.java:12)
>>
>> Ok, the error tells a number of things:
>> - you got the proper drivers loaded (Oracle JDBC, not ODBC)
>> - the database JDBC URL is at least correct enough that the
>> driver attempted to connect
>> - the connection attempt failed

(much data snipped)

>It looks like everything is fine on both sides so that's why I asked
>the original question.

Yep, everything seems to be in order. How about a host-based firewall
on either of the machines? Can you telnet from the client to port
1521 on the server?

>I suspect it has something to do with the tns names file which I dont
>have on the remote box,

No, Oracle JDBC doesn't require tnsnames; I recall it can utilise
tnsnames, but then the URL syntax would be different.

jct...@nb.sympatico.ca

unread,
Sep 5, 2006, 4:31:43 PM9/5/06
to
Massive snippage follows------

> Yep, everything seems to be in order. How about a host-based firewall
> on either of the machines? Can you telnet from the client to port
> 1521 on the server?
>
Don't laugh at me... but it was my XP Firewall that was blocking it.
Once I opened up port 1521 on my server I had no problems... thanks
for your help
0 new messages