java connectivity with mysql error

Posted by abson on Stack Overflow See other posts from Stack Overflow or by abson
Published on 2010-05-15T08:09:17Z Indexed on 2010/05/15 8:14 UTC
Read the original article Hit count: 311

Filed under:
|
|

I just started with the connectivity and tried this example. I have installed the necessary softwares. Also copied the jar file into the /ext folder.Yet the code below has the following error

import java.sql.*;
public class Jdbc00 {
  public static void main(String args[]){
        try {
      Statement stmt;

          Class.forName("com.mysql.jdbc.Driver");
          String url =
            "jdbc:mysql://localhost:3306/mysql"
            DriverManager.getConnection(url,"root", "root");

      //Display URL and connection information
      System.out.println("URL: " + url);
      System.out.println("Connection: " + con);

      //Get a Statement object
      stmt = con.createStatement();

      //Create the new database
      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 Jdbc00

But it gave the following error

D:\Java12\Explore>java Jdbc00
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at Jdbc11.main(Jdbc00.java:11)

Could anyone please guide me in correcting this?

© Stack Overflow or respective owner

Related posts about java

Related posts about jdbc