Results 1 to 6 of 6
  1. #1
    tariq9112003 is offline Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Default classnotfound exception in jdbc

    Hey guys.i am new to jdbc.i've used mysql.i installed my mysql connector/j in jdk1.6_0_11/jre/lib/ext path.I use netbeans to write my code;

    Here is my code
    Java Code:
    package jdbctrial;
    
    import java.sql.*;
    
    /**
     *
     * @author Tariq Ibrahim
     */
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args)throws Exception {
            // TODO code application logic here
            
            try {
          Statement stmt;
          Class.forName("com.mysql.jdbc.Driver");
          String url =
                "jdbc:mysql://localhost:3306/mysql";
          Connection con =
                         DriverManager.getConnection(
                                     url,"root", "");
           System.out.println("URL: " + url);
          System.out.println("Connection: " + con);
          stmt = con.createStatement();
          stmt.executeUpdate(
                           "CREATE DATABASE JunkDB");
          stmt.executeUpdate(
              "GRANT SELECT,INSERT,UPDATE,DELETE," +
              "CREATE,DROP " +
              "ON JunkDB.* TO 'auser'@'localhost' " +
              "IDENTIFIED BY 'drowssap';");
                con.close();
        }catch( Exception e ) {
          e.printStackTrace();
        }//end catch
      }//end main
    }//end class Jdbc11
    i get this exception when running


    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at jdbctrial.Main.main(Main.java:24)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    ClassNotFoundException: com.mysql.jdbc.Driver
    The class in the error message is not being found by the JVM. Find the jar file with that class and add it to the classpath.

  3. #3
    siva_vs_siva is offline Member
    Join Date
    Aug 2010
    Posts
    31
    Rep Power
    0

    Default

    set classpath with mysql connector;

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Quote Originally Posted by tariq9112003 View Post
    i've used mysql.i installed my mysql connector/j in jdk1.6_0_11/jre/lib/ext path.
    Don't do this.

    Have a lib directory in your Netbeans project folder, and stick your proect dependency jars in there. Do not dump stuff in the ext directory. That's lazy and so so wrong.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Why resurrect a thread that's pushing a year old.
    Especially to post something that really isn't all that good.

    Your error handling leaves a lot to be desired...you are failing to print any stack traces.
    You are also not closing resources ina finally block, which is likely to result in leaks.

    And finally, and possibly most egregious since I point out that this is incredibly poor practice in the post just prior to yours, you suggest sticking the JDBC MySQL jar files in the JDK ext directory!

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    Blog link spam deleted and spammer blocked for a month.

    db

Similar Threads

  1. Replies: 2
    Last Post: 12-09-2009, 09:58 AM
  2. ClassNotFound exception for inner class
    By hirop35 in forum New To Java
    Replies: 0
    Last Post: 11-30-2009, 05:25 AM
  3. classnotfound
    By mirror666 in forum New To Java
    Replies: 1
    Last Post: 11-11-2008, 02:54 PM
  4. Replies: 1
    Last Post: 10-16-2008, 02:09 PM
  5. JDBC - Exception handling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-05-2007, 04:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •