Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Error

 
Atul Oberoi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree, chances are you just need a newer version of the oracle drivers.
 
Atul Oberoi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you fix your display name please.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Mahesh Malviya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a few thoughts on this but unfortunately my time has been taken writing warnings on display names
 
Makarand Parab
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Atul Oberoi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.....
 
Atul Oberoi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34179
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Atul,
Great. Thanks for posting the solution.

And thanks for changing your display name. Welcome to JavaRanch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic