471,601 Members | 1,191 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,601 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 6283
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

Post your reply

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

Similar topics

9 posts views Thread by tiyaramunna | last post: by
reply views Thread by CCCYYYY | last post: by

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.