Accorting to MySql manual and web site I modified the environment variable for installing JConnector for mysql as follows :


C:\Program Files\Java\mysql-connector-java-5.0.7\mysql-connector-java-5.0.7-bin.jar

where my MySql connector Folder is placed on Java folder in program files (I put there willingly)

But actually when I want to do any testing program checking whether mysqlConnection is ok I get NoClassDefFound Exception that mean connection is not established and jConnector is not installed properly

PLz Tell me how can I install JConnector 5.0 I really need help

Here is my code

import java.sql.*;
import java.util.*;
import java.lang.Exception;

public class prog1 {

public prog1() {

public static void main (String[] args) {

try {

String url="jdbc:mysql://localhost/company?user=root&password=password";
Connection dbcon=DriverManager.getConnection(url,"root","password");
Statement smnt=dbcon.createStatement();
String query="select ENAME from emp";
ResultSet rs=smnt.executeQuery(query);
ResultSetMetaData resmetadata=rs.getMetaData();
int n=resmetadata.getColumnCount();
System.out.println("The no of employee in the company"+n);

catch(ClassNotFoundException exp)
System.out.println("The Error is"+exp);

catch(SQLException sqle)
System.out.println("The Error is"+sqle);


Edited 3 Years Ago by happygeek: fixed formatting

You need to specify the full name of the driver in the Class.forName() call:


have you placed the .jar file here???


i think you need to do that

I have solved the problem when working with netbeans and jcreator but for command line the scenario is the same

& I ve placed what you ve said to put in jre but nothing happened


Do not do this, it is wrong advice and bad idea to mess up with Java installation directory.

how did u solve that, plz tell me. even m facing the same problem

As you did not explain your problem I can give you general direction. Have look at this post which gives you quick guidelines how to add connector to your project in NetBeans. If this is not what you looking for please, explain more in depth your issue with database connector

This question has already been answered. Start a new discussion instead.