Results 1 to 4 of 4
  1. #1
    Burglar_Cat is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default MySqlProblem ClassNotFound

    Hi,Seniors:
    I'm a fresh who are newly to jdbc. I write my first toyprogram to connect mysql database and have errors. the code as follows:



    import java.sql.*;


    public class TestJDBC {

    public static void main(String[] args) {
    try {
    Class.forName("com.mysql.jdbc.driver").newInstance ();
    } catch (InstantiationException e) {
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
    try {
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/MyData?" +
    "user=root&password=20032206");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("Select * from dept");
    while(rs.next()) {
    System.out.println(rs.getString("deptno"));
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }



    }

    }


    and console response as follows:

    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 TestJDBC.main(TestJDBC.java:8)
    10
    20
    30
    40
    50
    60


    My puzzle is I have connected to DB succesfully. But why ClassNotFound Exception exist? I hope for answers . thanks

  2. #2
    Burglar_Cat is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default

    Something addition: 10 20 30 40 50 60 are data I retrieve from database;

    And I hope I can join in a java group in msn, that will be easy for discuss.

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    The driver class name starts with a capital D. You should have used "com.mysql.jdbc.Driver"

  4. #4
    Burglar_Cat is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

Similar Threads

  1. ClassNotFound exception for inner class
    By hirop35 in forum New To Java
    Replies: 0
    Last Post: 11-30-2009, 05:25 AM
  2. Client to Server, ClassNotFound Package Problem
    By pwnzer in forum New To Java
    Replies: 3
    Last Post: 11-07-2009, 09:17 PM
  3. Replies: 0
    Last Post: 10-12-2009, 05:39 AM
  4. classnotfound
    By mirror666 in forum New To Java
    Replies: 1
    Last Post: 11-11-2008, 02:54 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
  •