File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with conn to oracle

 
Mahesh Pinnamaneni
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have u add the classpath of your Oracle JDBC driver, while compiling your application? :roll:
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set CLASSPATH.;location to jar file of oracle jdbc;%CLASSPATH%
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys,
the CLASSPATH ultimately made my page work.
regards,
Mahesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic