| Author |
Java - Oracle Connectivity problem
|
Rajagopal Iyer
Greenhorn
Joined: Feb 13, 2004
Posts: 1
|
|
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
Joined: Oct 29, 2001
Posts: 8263
|
|
|
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
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
Jason Cox
Ranch Hand
Joined: Jan 21, 2004
Posts: 287
|
|
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.
|
<a href="http://www.unfetteredblather.com" target="_blank" rel="nofollow">Unfettered Blather</a> - Updated daily nonsense
|
 |
 |
|
|
subject: Java - Oracle Connectivity problem
|
|
|