• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

runtime NoClassDefFoundError when trying jdbc

 
david hw wang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
runtime java.lang.NoClassDefFoundError when trying jdbc
---------------
Hi, I am fresh new in java and, when I try to connect with Access Database, I got the runtime Error (compiled fine)

It bothered me three days, and I am really tired,

Thank you first

---------------

that's what I have done:

jdk 1.4

----------------------

CLASSPATH:
e:\sun\appserver;E:\Sun\Tomcat 5.5\webapps\tsf\WEB-INF\classes

JAVA_HOME:
e:\sun\appserver\jdk

----------------

tools.jar in e:\sun\appserver\jdk\lib

---------------

built up a dababase with access : test.mdb
with one table customer (two colums: cust_id,cust_name)

---------------

setup odbc in winXP homeEdition


control pannel --> administrative tools --> data source(ODBC)-->
system DSN--> Mrcrosoft Access Driver(*.mdb) -->
with dataSourceName : testconnect ; and I put the description;
select database :test.mdb;
advanced option with loginName tester ;password: tester

-------------------
then I copied the following from internet:

-------------------

import java.sql.*;

class JdbcTest1{

public static void main(String args[]){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc dbc:testconnect";
Connection conc = DriverManager.getConnection(url, "tester","tester");
statement stmt=conc.createStatement();
ResultSet rs=stmt.executeQuery("select * from customer");

while(rs.next()){
String s1=rs.getString("cust_id");
String s2=rs.getString("cust_name");
System.out.println(s1+"\t"+s2);
}
rs.close();
stmt.close();
conc.close();
}//try
catch(Exception e){
System.out.println(e);
}//catch
}//main
}
-------------------------------
javac JdbcTest1.java fine
---------------------------------
java JdbcTest1
Exception in thread main java.lang.NoClassDefFoundError: JdbcTest1

-------------------------------
 
Zip Ped
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to have used the Statement class as "statement stmt" and not "Statement stmt". Please correct it and see if it works.
 
david hw wang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much for reply

when I post it here, I made the mistake, it is

Statement stmt=conc.createStatement();

,
 
david hw wang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it better to move my question to JDBC ?
but I don't know how to move it
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to move - this isn't a JDBC problem. The JVM doesn't find your class in the classpath.

Try to change it to

.;e:\sun\appserver;E:\Sun\Tomcat 5.5\webapps\tsf\WEB-INF\classes

notice the ".;" at the beginning - without that Java doesn't look in the current directory.
 
david hw wang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot,
I put ".;" but it still doesn't work, the same err msg
 
david hw wang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS !!! it works!!!

just now, I didn't reboot, classpath cann't be reset?
is that true I have to reboot to reset the classpath? because I use "set" command in command line, and it doesn't work

thanks again! and I really appreciate all your help!
have a nice day!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"davidhw hww",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Zip Ped
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to reboot if you are using Win XP. I am assuming you are running from your console, so all you need to is close the DOS prompt window and start a new one.
 
david hw wang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!

First, according the rules of the ranch, I changed the display name.
and ,
I did run command line from a console, I think that's why my classpath didn't reset even I use set command.

Thanks a lot to all of your help!
have a nice day
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic