File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes runtime  NoClassDefFoundError  when trying jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "runtime  NoClassDefFoundError  when trying jdbc" Watch "runtime  NoClassDefFoundError  when trying jdbc" New topic

runtime NoClassDefFoundError when trying jdbc

david hw wang

Joined: Mar 14, 2006
Posts: 7
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


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



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[]){
String url = "jdbc dbc:testconnect";
Connection conc = DriverManager.getConnection(url, "tester","tester");
statement stmt=conc.createStatement();
ResultSet rs=stmt.executeQuery("select * from customer");

String s1=rs.getString("cust_id");
String s2=rs.getString("cust_name");
catch(Exception e){
javac fine
java JdbcTest1
Exception in thread main java.lang.NoClassDefFoundError: JdbcTest1

Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
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

Joined: Mar 14, 2006
Posts: 7
thank you very much for reply

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

Statement stmt=conc.createStatement();

david hw wang

Joined: Mar 14, 2006
Posts: 7
is it better to move my question to JDBC ?
but I don't know how to move it
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
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.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
david hw wang

Joined: Mar 14, 2006
Posts: 7
thanks a lot,
I put ".;" but it still doesn't work, the same err msg
david hw wang

Joined: Mar 14, 2006
Posts: 7
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

Joined: Jan 10, 2002
Posts: 63866

"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.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
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

Joined: Mar 14, 2006
Posts: 7
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
I agree. Here's the link:
subject: runtime NoClassDefFoundError when trying jdbc
It's not a secret anymore!