By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,219 Members | 1,292 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,219 IT Pros & Developers. It's quick & easy.

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

P: 87

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


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 {
conn = DriverManager.getConnection(url+dbName,userName,pa ssword);
System.out.println("Connected to the database");
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from customer");
System.out.println(reset.getString(1)+ "\t\t" + reset.getString(2));
System.out.println("Disconnected from database");
} catch (java.lang.ClassNotFoundException e) {


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.


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
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,216
Java is case sensitive, even under Windows, so be careful to write MySQLConnect, or whatever is the exact class name.
Feb 16 '08 #2

P: 87

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

Expert 100+
P: 1,216
Are you including the current directory (".") in your list for classpath?
Feb 17 '08 #4

Post your reply

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