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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ananthu
    New Member
    • Sep 2007
    • 87

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

    Hi

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

    Codings:

    import java.sql.Connec tion;
    import java.sql.Driver Manager;
    import java.sql.Result Set;
    import java.sql.Statem ent;

    public class MysqlConnect {

    public static void main(String[] args)throws Exception{
    System.out.prin tln("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(d river);
    conn = DriverManager.g etConnection(ur l+dbName,userNa me,password);
    System.out.prin tln();
    System.out.prin tln("Connected to the database");
    System.out.prin tln();
    Statement stmt = conn.createStat ement();
    ResultSet reset = stmt.executeQue ry("select * from customer");
    System.out.prin tln("Name\t\tAg e");
    System.out.prin tln();
    while(reset.nex t()){
    //System.out.prin tln(reset.getSt ring(1));
    //System.out.prin tln(reset.getSt ring(2));
    System.out.prin tln(reset.getSt ring(1)+ "\t\t" + reset.getString (2));
    }
    conn.close();
    System.out.prin tln();
    System.out.prin tln("Disconnect ed from database");
    } catch (java.lang.Clas sNotFoundExcept ion e) {
    e.printStackTra ce();
    }
    }

    }

    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\ja va\jdk1.6.0_01\ bin>javac -classpath ";.\program files\mysql-connector-java-5.6.0_01" mysqlconnect

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

    Exception in thread "main" java.lang.nocla ssdeffound 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...
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Java is case sensitive, even under Windows, so be careful to write MySQLConnect, or whatever is the exact class name.

    Comment

    • Ananthu
      New Member
      • Sep 2007
      • 87

      #3
      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

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Are you including the current directory (".") in your list for classpath?

        Comment

        Working...