473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Exception in thread "main" java.lang.noclassdeffound error

87
Hi

This is my codings in order to access mysql database from java.

Codings:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class MysqlConnect {

public static void main(String[] args)throws Exception{
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3309/";
String dbName = "ananthu";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "sa";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url+dbName,userName,pa ssword);
System.out.println();
System.out.println("Connected to the database");
System.out.println();
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from customer");
System.out.println("Name\t\tAge");
System.out.println();
while(reset.next()){
//System.out.println(reset.getString(1));
//System.out.println(reset.getString(2));
System.out.println(reset.getString(1)+ "\t\t" + reset.getString(2));
}
conn.close();
System.out.println();
System.out.println("Disconnected from database");
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
}
}

}

I have mysqlconnector 5.0.7 jar file and i have placed it in program files folder.

The following is the execution of my codings.

Execution:

c:\program~1\java\jdk1.6.0_01\bin>javac -classpath ";.\program files\mysql-connector-java-5.6.0_01" mysqlconnect

c:\progra~1\java\jdk1.6.0_01\bin>java -classpath ";.\program files\mysql-connector-java-5.6.0_01" mysqlconnect

Exception in thread "main" java.lang.noclassdeffound error: mysqlconnect

-----


The above error occurs only during running the program and not in compilation time.

How to rectify the error and run the program successfully?

Please help me...
Feb 16 '08 #1
3 6416
BigDaddyLH
1,216 Expert 1GB
Java is case sensitive, even under Windows, so be careful to write MySQLConnect, or whatever is the exact class name.
Feb 16 '08 #2
Ananthu
87
Hi

The same error occurs even when i give the class name in case sensitive manner also during execution.

Compilation is Successful but not running.

What to do?

Please give me the solution
Feb 17 '08 #3
BigDaddyLH
1,216 Expert 1GB
Are you including the current directory (".") in your list for classpath?
Feb 17 '08 #4

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

Similar topics

0
by: Phillip Montgomery | last post by:
Hello all; I'm trying to debug an issue with a java script called, SelectSockets. It appears to be a fairly common one found on the web. I downloaded the SGI Java v1.4.1 installation from SGI's...
1
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...
12
nomad
by: nomad | last post by:
Hi everyone; My Class has ended and I was not able to solve this problem in time, and I would still like to solve it. I got these error code. Exception in thread "main"...
9
by: jith87 | last post by:
What is ths error.????? I m nw loading the JDBC driver for connection with MySql. Exception in thread "main" java.lang.NoClassDefFoundError: MySQLJDBCDriverTest
9
by: tiyaramunna | last post by:
I am trying to configure my system with Java program just to practice on the coding....when i compile a test.java program i am able to see the class file but i cant run the program ... I am getting...
4
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...
1
by: jimgym1989 | last post by:
I dont get it..why is the error: Exception in thread "main" java.util.InputMismatchException this is my code /** * @(#)textFileRead.java * * * @author * @version 1.00 2008/10/17 */
3
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at...
1
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.