• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java - Oracle Connectivity problem

 
Rajagopal Iyer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble connecting Java 1.4 to Oracle 9i database on my Pentium 4 machine (O/S Win98).
I set the PATH to "e:\PROGRAM FILES\Oracle\jdbc\lib\classes12.zip" and the CLASSPATH to "e:\PROGRAM FILES\Oracle\jdbc\lib\nls_charset12.zip"
I then tried to compile and execute following program :
import java.sql.*;
import oracle.jdbc.driver.*;
class Myjdbc {
public static void main(String args[]) throws Exception {
try {
Class.forname("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc racle:thin:@BLUETIT_ATMP:1529:atmp";
Connection con = DriverManager.getConnection(url,"atm","keep0ut");
Statement stmt = con.createStatement();
stmt.executeUpdate("CREATE TABLE BOOKS "+
"(BOOKNAME VARCHAR2(30)");
stmt.executeUpdate("INSERT INTO BOOKS "+ "VALUES('Java Prog')");
}
catch (Exception e) {
System.out.println(e);
}
}
}
I get the following error at runtime :
Exception in thread "main" java.lang.NoClassDefFoundError : Myjdbc
Please let me know how to proceed.
Thanks
Rajagopal Iyer
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't a JDBC problem, it's a classpath problem. The JVM can't find your class, Myjdbc. You probably don't have the current directory (i.e. ".") in the classpath. If you need more instruction, consult the FAQ: How to set the Classpath
 
Jason Cox
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised that is the only error you are getting.
Class.forname should be Class.forName - note the difference in capitalization.
You are importing the Oracle driver but you never use it. The oracle import is worthless.
Instead of using Class.forName (which is unreliable) it would be better to do the following -
DriverManager.registerDriver(new OracleDriver());
This also avoids the ever annoying ClassNotFoundException.
Even better would be to use the Oracle Connection pooling, but that's beyond the scope of this topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic