473,612 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java.lang.NoCla ssDefFoundError catch-22

3 New Member
I have a test program that compiles but does not run.
Here is the code which I grabbed from from a web site:
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.*;
  4. import java.util.*;
  5. import java.sql.*;
  6.  
  7. public class ColumnName{
  8.   public static void main(String[] args) {
  9.     System.out.println("Getting Column Names Example!");
  10.     Connection con = null;
  11.     String url = "jdbc:mysql://localhost:3306/";
  12.     String db = "jdbctutorial";
  13.     String driver = "com.mysql.jdbc.Driver";
  14.     String user = "root";
  15.     String pass = "root";
  16.     try{
  17.       Class.forName(driver);
  18.       con = DriverManager.getConnection(url+db, user, pass);
  19.       try{
  20.         Statement st = con.createStatement();
  21.         ResultSet rs = st.executeQuery("SELECT * FROM employee6");
  22.         ResultSetMetaData md = rs.getMetaData();
  23.         int col = md.getColumnCount();
  24.         System.out.println("Number of Column : "+ col);
  25.         System.out.println("Columns Name: ");
  26.         for (int i = 1; i <= col; i++){
  27.           String col_name = md.getColumnName(i);
  28.           System.out.println(col_name);
  29.         }
  30.       }
  31.       catch (SQLException s){
  32.         System.out.println("SQL statement is not executed!");
  33.       }
  34.     }
  35.     catch (Exception e){
  36.       e.printStackTrace();
  37.     }
  38.   }
  39. }
  40.  
Here are the runs:

1 WITH classpath NOT set

java ColumnName
Getting Column Names Example! <-output from line 9
java.lang.Class NotFoundExcepti on: com.mysql.jdbc. Driver
at java.net.URLCla ssLoader$1.run( URLClassLoader. java:217)
at java.security.A ccessController .doPrivileged(N ative Method)
at java.net.URLCla ssLoader.findCl ass(URLClassLoa der.java:205)
at java.lang.Class Loader.loadClas s(ClassLoader.j ava:321)
at sun.misc.Launch er$AppClassLoad er.loadClass(La uncher.java:294 )
at java.lang.Class Loader.loadClas s(ClassLoader.j ava:266)
at java.lang.Class .forName0(Nativ e Method)
at java.lang.Class .forName(Class. java:186)
at ColumnName.main (ColumnName.jav a:17)

RUN 2 with classpath set
java -classpath /opt/Java/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar ColumnName
Exception in thread "main" java.lang.NoCla ssDefFoundError : ColumnName
Caused by: java.lang.Class NotFoundExcepti on: ColumnName
at java.net.URLCla ssLoader$1.run( URLClassLoader. java:217)
at java.security.A ccessController .doPrivileged(N ative Method)
at java.net.URLCla ssLoader.findCl ass(URLClassLoa der.java:205)
at java.lang.Class Loader.loadClas s(ClassLoader.j ava:321)
at sun.misc.Launch er$AppClassLoad er.loadClass(La uncher.java:294 )
at java.lang.Class Loader.loadClas s(ClassLoader.j ava:266)
Could not find the main class: ColumnName. Program will exit.
Mar 8 '11 #1
1 3474
James Kalmadge
3 New Member
Hey,

Found the answer at another similar post here.
Or at least a work-around.

javac -classpath /opt/Java/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar ColumnName.java && java -classpath .:/opt/Java/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar ColumnName

Apparently, this is a classpath issue but I am happy with the work-around for now.
Mar 8 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
167093
by: Lem | last post by:
I get the error Exception in thread "main" java.lang.NoClassDefFoundError when I type java app2 in the command prompt. I've tried moving to the jre directory and typed java c:\app2\app2, but it gives me the same exception. What could be the problem? Thanks in advance, Lem
1
9107
by: Andy Howells | last post by:
Can anybody help me on this? I am getting the below error but have not got a clue why. The file in my classpath eing used has the class that it says is not defined. Any ideas? I am running java version 1.4.0 and WMQ Series version 5.3 with CSD04. Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/mq/server/MQSESSION at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java:67) at...
0
4494
by: Shawn | last post by:
I am getting the following error with a Java Applet being served out by IIS over HTTPS/SSL using a Verisign certificate: java.lang.NoClassDefFoundError: javax/help/HelpSetException at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590) at java.lang.Class.getConstructor0(Class.java:1762) at java.lang.Class.newInstance0(Class.java:276) at...
3
6524
by: NathanK | last post by:
Hi Guys, im starting out in java and i'm getting the error: Exception in thread "main" java.lang.NoClassDefFoundError: blurf if i run "javac blurf.java", it compiles fine and without any troubles. when i try to run it (its a simple hello world program) i get the above error.
1
47605
by: greg.knaddison | last post by:
Hi, I'm trying to use the httpclient within Jython (see http://jakarta.apache.org/commons/httpclient/ for more information on the httpclient). My Jython version is: Jython 2.1 on java1.4.2_04 (JIT: null) My Java version is:
3
15152
by: Bernd Oninger | last post by:
When I run the successfully compiled java source shown at the end I got a runtime error: Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/Content Where is the missing class ? I copied the newest jdom.jar from newest JDOM release b10 to the folder jdk\jre\lib\endorsed
0
3682
by: HiteshMehra | last post by:
Hi all, I am getting an error while trying to connect to the MQ. The error is java.lang.NoClassDefFoundError: com/ibm/mq/server/MQSESSION at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java:68) at com.ibm.mq.MQSESSION.getSession(MQSESSION.java:493) at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:155) at...
1
2491
by: Nimesh dadhaniya | last post by:
Hi All, I am trying to learn EJB's on my own. I installed the WebLogic Server Trial version and then wrote the Home Interface, Component Interface and the Bean Class. Now I started the WebLogic server and tried and create the deployment descriptor.. I am getting the error below even after I set the classpath. Is there any other correct way to set the classpath? C:\bea\jdk150_04\bin\ejb\demo>set...
4
14715
by: jmitch89 | last post by:
I don't why I get this error: Exception in thread "main" java.lang.NoClassDefFoundError The statement below works just fine: java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar";CurrentStrobe.jar com.visionpro.currentstrobe.CurrentStrobeApp However, the statement below produces the error: java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar" -jar CurrentStrobe.jar Exception in thread "main"...
1
10064
by: rajujrk | last post by:
Hai All, I am Having a problem in the following... import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.io.FileUtils; import java.io.IOException;
0
8162
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8605
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8246
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5532
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.