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

    Default ClassNotFound exception

    Hi,

    I tried to connect to database using java. In main function I have a following code:

    String url = "jdbc:mysql://localhost:3306/";
    String driver = "com.mysql.jdbc.Driver";
    String dbname = "probna_bp";
    try{
    Class.forName(driver).newInstance();
    Connection kon=DriverManager.getConnection(url+dbname, "root", "");
    Statement izraz=kon.createStatement();
    izraz.executeUpdate("insert into korisnici values(1, 'mujo', 'mujina');");
    kon.close();
    }
    catch(Exception e){
    e.printStackTrace();
    }

    But, when I run this, it shows me exception:

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

    com.mysql.jdbc.Driver is driver that I use to connect

    What could be a problem?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I suspect that the driver's jar may not be on your classpath. You will need to place it on the classpath for this to work and how you do this will depend on how you are running your code. Are you using an IDE such as NetBeans or Eclipse or are you compiling and running on the command line?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Also, you'll want to reply to the helpful responses to your post from yesterday. Doing this will encourage others to help you in the future. Just a little suggestion.

  4. #4
    aldm is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default

    Yes, that was a problem. I'm using Net Beans IDE. I just imported mysql-connector in project and it works.
    Thank you very much for answer and for suggestion. I'm new to java
    and this forums. so sorry for not replying :)

    Thanks again

Similar Threads

  1. classnotfound exception in jdbc
    By tariq9112003 in forum Advanced Java
    Replies: 5
    Last Post: 06-07-2011, 10:47 AM
  2. MySqlProblem ClassNotFound
    By Burglar_Cat in forum JDBC
    Replies: 3
    Last Post: 05-13-2010, 10:31 AM
  3. ClassNotFound exception for inner class
    By hirop35 in forum New To Java
    Replies: 0
    Last Post: 11-30-2009, 05:25 AM
  4. Replies: 0
    Last Post: 10-12-2009, 05:39 AM
  5. 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
  •