Results 1 to 3 of 3
  1. #1
    providence is offline Member
    Join Date
    Oct 2010
    Location
    Canada
    Posts
    20
    Rep Power
    0

    Default ClassNotFoundException...

    I have been working for hours trying to get rid of this error:

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    And yes, I do have the build path configured in my IDE (eclipse), I also have copied the connector.jar file into just about every conceivable folder in my project. At a complete loss here.. Please note, Im trying to write to the database from a servlet. Anyone know whats goin' down?

    The code that generates the error is below, if you need further code samples I'll be more than happy to post 'em:

    Java Code:
    String dbName = "testdb";
    	String url = "jdbc:mysql://localhost:3306/";
    	String username = "...";
    	String password = "...";
    	Connection con = null;
    	String driver = "com.mysql.jdbc.Driver";
    	Class.forName(driver).newInstance();

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Yes. you haven't properly configured the "execution path". I.E. Add the jar as a reference/library, do not just add it to the "build path" (which is wrong anyway since the "build path" describes what should be compiled in eclipse, not where to find the libraries) and the jar is not needed for compilation anyway, as no where in your code do you directly reference one of the classes in it. You have a String containing a classname in it, and a lot of references to interfaces defined in the standard language, so you do not need the jar during compilation, only during execution.

  3. #3
    providence is offline Member
    Join Date
    Oct 2010
    Location
    Canada
    Posts
    20
    Rep Power
    0

    Default

    Thanks, that was indeed part of the problem. I also had to add the .jar to the tomcat/lib folder.

Similar Threads

  1. ClassnotFoundException
    By balaji shan in forum Java Servlet
    Replies: 8
    Last Post: 01-19-2011, 03:47 PM
  2. classNotFoundException
    By jyothi.priyanka in forum NetBeans
    Replies: 5
    Last Post: 08-24-2010, 10:13 AM
  3. ClassNotFoundException
    By oontvoo in forum Java Applets
    Replies: 7
    Last Post: 05-13-2010, 11:09 PM
  4. ClassNotFoundException
    By Edward in forum New To Java
    Replies: 2
    Last Post: 06-29-2009, 07:08 PM
  5. ClassNotFoundException
    By Chezelle in forum Java Applets
    Replies: 5
    Last Post: 12-24-2008, 04:26 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
  •