aspose file tools*
The moose likes Beginning Java and the fly likes Problem with conn to oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with conn to oracle" Watch "Problem with conn to oracle" New topic
Author

Problem with conn to oracle

Mahesh Pinnamaneni
Ranch Hand

Joined: Jul 02, 2004
Posts: 100
hai
i have a problem connecting to oracle 9i.
here is the code:-

import java.sql.*;
class TestThinApp {
public static void main (String args[])
throws ClassNotFoundException, SQLException
{
Connection conn=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("connection success");
}catch(Exception e)
{
System.out.println("Inside class.forname ");
System.out.println(e);
}
try{
conn = DriverManager.getConnection(
"jdbc racle:thin:@10.10.20.10:1521:ero","mahesh","mahesh");
}catch(Exception e)
{ System.out.println("Inside Drivermanager.getconn ");
System.out.println(e);
}
}
}

i am getting an error like:
Inside class.forname
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
Inside Drivermanager.getconn
java.sql.SQLException: No suitable driver


plz solve this.
thanks and regards,
mahesh
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Have u add the classpath of your Oracle JDBC driver, while compiling your application? :roll:


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
set CLASSPATH.;location to jar file of oracle jdbc;%CLASSPATH%


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by Ko Ko Naing:
Have u add the classpath of your Oracle JDBC driver, while compiling your application? :roll:


Ko Ko,
He is facing a Exception during runtime, it is not a compile time problem.


Groovy
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by Pradeep Bhat:


Ko Ko,
He is facing a Exception during runtime, it is not a compile time problem.


Yes, But when program call Class.forName("oracle.jdbc.driver.OracleDriver");

It's MUST find all library from CLASSPATH environment.

So, you should be configed CLASSPATH refer to oracle jdbc driver.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Pradeep Bhat:


Ko Ko,
He is facing a Exception during runtime, it is not a compile time problem.


Well, Pradeep, as Somkiat mentioned above, even though it is not compile time problem, if Mahesh did not add the classpath, how can his application find the driver?

Since "oracle.jdbc.driver.OracleDriver" is a String, it will be able to pass the compile time, but not the runtime...
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Well, Pradeep, as Somkiat mentioned above, even though it is not compile time problem, if Mahesh did not add the classpath, how can his application find the driver?


Right, but your statement confused me.
Mahesh Pinnamaneni
Ranch Hand

Joined: Jul 02, 2004
Posts: 100
thanks guys,
the CLASSPATH ultimately made my page work.
regards,
Mahesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with conn to oracle