wood burning stoves 2.0*
The moose likes JDBC and the fly likes JDBC Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Error" Watch "JDBC Error" New topic
Author

JDBC Error

Atul Oberoi
Greenhorn

Joined: Oct 14, 2005
Posts: 19
Hi Guys!
Iam facing a problem while accessing Oracle8 through JDBC. I have set classpath as d:\oracle\jdbc\lib\classes102.zip but still am getting errors.
I guess it is loading the driver but could not make a connection.I have used thin(Type 4) driver.It shows following errors :-

java.sql.SQLException: Io exception: The Network Adapter could not
establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:169)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:211)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:324)
at
oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:266)
at
oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)


Please help me out at the earliest.
[ October 14, 2005: Message edited by: Bear Bibeault ]
ra ma
Greenhorn

Joined: Sep 28, 2005
Posts: 1
Originally posted by java tyke:
Hi Guys!
Iam facing a problem while accessing Oracle8 through JDBC. I have set classpath as d:\oracle\jdbc\lib\classes102.zip but still am getting errors.
I guess it is loading the driver but could not make a connection.I have used thin(Type 4) driver.It shows following errors :-

java.sql.SQLException: Io exception: The Network Adapter could not
establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:169)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:211)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:324)
at
oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:266)
at
oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)


Please help me out at the earliest.


hai,

use classes12.zip u setclasspath=classes12.zip if will run
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"java tyke" and "ra ma",

We're a friendly bunch at the Ranch, but we take display names very seriously.

Your display name must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profiles an select a valid display name. Accounts with invalid display names get deleted.

thanks,
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I agree, chances are you just need a newer version of the oracle drivers.
Atul Oberoi
Greenhorn

Joined: Oct 14, 2005
Posts: 19
I have used classes12.zip but still its not working.
my code is :-
import java.sql.*;
class creation
{
public static void main(String[] args)
{
Connection con;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
System.out.println("Driver Loaded");
con = DriverManager.getConnection("jdbc racle:thin:localhost","scott","tiger");
if (con==null)
System.out.println("Problem");
}
catch (Exception e)
{
System.out.println(e);
}

}
}

It says driver loaded but its not entering the connection function and therby throws above exception which i posted earlier.
Can anyone suggest me and give a suitable reason for this.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Can you fix your display name please.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You are running an Oracle instance on your local machine aren't you? You might also want to double-check your connection URL - it seems to be missing a database name and the port to connect over. (and you probably want to pay attention to David O'Meara's post about your name).


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mahesh Malviya
Ranch Hand

Joined: Aug 20, 2004
Posts: 39
Hi,
I know that defuat port for oracle is 1521. I want to know if we do not provide port no in connection url then is it go for the defualt 1521?

Or we have to specify.

Thanks in advance
Mahesh Malviya
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I have a few thoughts on this but unfortunately my time has been taken writing warnings on display names
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Hi java tyke
As per my knowledge, this exception is thrown when the oracle database m/c and your m/c on which the code is running are on different n/w. Usually when i work from home, without connecting to the office n/w using vpn and try to run the java program which has database connectivity it gives me the same error. Once i connect to the office n/w it starts working fine. I hope you are getting what i mean.

Let me know if you have any questions

Regards
Makarand Parab
Padma Lalwani
Ranch Hand

Joined: Nov 02, 2004
Posts: 49
On the machine the oracle server is running on, the tnsnames.ora must be configured to have valid host, port and service_name/SID. You can then refer to these in your JDBC connection parameters
This file will be found in network/admin folder of your Oracle installation and also there is also a sample file shipped along with Oracle
Padma
Atul Oberoi
Greenhorn

Joined: Oct 14, 2005
Posts: 19
Hi again!!

I think Makrand and Padma , u both can help me out regarding this.Padma please tell me how to configure *.ora file for host, port and tsn name and let me know a simple code to execute this. I have oracle in my local m/c so i guess there should be no problem.
Makrand i think u can help me out in class path settings and checking various parameters to execute this. Is there something to be done in Registry?
iam trying this from past 5 days but no success.

Awaiting for ur replies.
Thanks!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

"java tyke",

You have been warned to change your display name to conform to Ranch standards twice in this very topic. This is your third and final warning. The naming rule is not a suggestion nor is it a joke.

Read the JavaRanch Naming Policy and adjust your display name to match it prior to your next post or risk having your account closed.

bear
Forum bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Atul Oberoi
Greenhorn

Joined: Oct 14, 2005
Posts: 19
Sorry Guys!!
Now that i hv read the naming policy , i hv changed my display name.
Plz help me out to resolve my JDBC problem


Thanks,
Atul
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Are you running on Linux? I read a thread suggesting this can be caused if you are running the wrong listener on the server.

Also, are you running remotely or through a firewall or other security? Oracle connections are initially made on port 1521 but the server then negotiates a new port. If this redirection is not working you'll get strange behaviour. It is possible to disable the port negotiation and keep using 1521.
Dilpreet Singh
Greenhorn

Joined: Jan 21, 2004
Posts: 6
Just Unjar(zip) the file and check that all the class files exist if not
then either copy from other folders or download the latest jar(zip) file.
That is how I fixed it when I.....


DIL-A-NADAN
Atul Oberoi
Greenhorn

Joined: Oct 14, 2005
Posts: 19
Thanks guys for ur suggestions. I got it right by just modifying the url of my code. Actually at the time of installation of Oracle i provided SID which i forgot to specify in the url. When i just tried with my SID it worked finally :-) Whooo!! At last i got connection .


Atul..
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30596
    
154

Atul,
Great. Thanks for posting the solution.

And thanks for changing your display name. Welcome to JavaRanch!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
GeeCON Prague 2014
 
subject: JDBC Error