Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Java MySQL Driver issue

Java MySQL Driver issue

Scheduled Pinned Locked Moved Java
databasehelpjavamysqlcom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khurram_shahzad
    wrote on last edited by
    #1

    Hi, i am trying to connect to MySQL database mysql using JAVA .. using code given below,

    import java.sql.*;

    public class dbExample{
    public static void main(String[] args) {
    System.out.println("Listing all table name in Database!");
    Connection con = null;
    String url = "jdbc:mysql://localhost:3306/";
    String db = "mydb";
    String driver = "com.mysql.jdbc.Driver";
    String user = "root";
    String pass = "root";
    try{
    Class.forName(driver);
    con = DriverManager.getConnection(url+db, user, pass);
    }
    catch (Exception e){
    e.printStackTrace();
    }
    }
    }

    I've picked this example from internet .. and there lot more example i tried using this same driver String driver = "com.mysql.jdbc.Driver"; But this code all other i tried gives me error Driver Class not found ... at this statment Class.forName(driver); ..... and similarly on trying this driver sun.jdbc.odbc.JdbcOdbcDriver the above mentioned statment Class.fonName ... executes but then it gives error on statment con = DriverManager.getConnection(url+db, user, pass); error is No suitable drive found for jdbc:mysql://localhost:3306/mydb I'm very much confused and tried it toooooo many time in diffrents ways that i could but still unable to create successfull database connection. I've tried this using notepad / Netbeans both and both on WINDOWS7 and XP ... and both give same error to me .... :( :( :( :( Please Please PLease give me any solution .... I shell be very very Thanksfull to you.

    M 1 Reply Last reply
    0
    • K khurram_shahzad

      Hi, i am trying to connect to MySQL database mysql using JAVA .. using code given below,

      import java.sql.*;

      public class dbExample{
      public static void main(String[] args) {
      System.out.println("Listing all table name in Database!");
      Connection con = null;
      String url = "jdbc:mysql://localhost:3306/";
      String db = "mydb";
      String driver = "com.mysql.jdbc.Driver";
      String user = "root";
      String pass = "root";
      try{
      Class.forName(driver);
      con = DriverManager.getConnection(url+db, user, pass);
      }
      catch (Exception e){
      e.printStackTrace();
      }
      }
      }

      I've picked this example from internet .. and there lot more example i tried using this same driver String driver = "com.mysql.jdbc.Driver"; But this code all other i tried gives me error Driver Class not found ... at this statment Class.forName(driver); ..... and similarly on trying this driver sun.jdbc.odbc.JdbcOdbcDriver the above mentioned statment Class.fonName ... executes but then it gives error on statment con = DriverManager.getConnection(url+db, user, pass); error is No suitable drive found for jdbc:mysql://localhost:3306/mydb I'm very much confused and tried it toooooo many time in diffrents ways that i could but still unable to create successfull database connection. I've tried this using notepad / Netbeans both and both on WINDOWS7 and XP ... and both give same error to me .... :( :( :( :( Please Please PLease give me any solution .... I shell be very very Thanksfull to you.

      M Offline
      M Offline
      Min Liao
      wrote on last edited by
      #2

      your code is absolutely right,but if you use "com.mysql.jdbc.Driver", you should add jdbc driver for mysql in your lib. download jdbc driver jar here: http://dev.mysql.com/downloads/connector/j/

      K 1 Reply Last reply
      0
      • M Min Liao

        your code is absolutely right,but if you use "com.mysql.jdbc.Driver", you should add jdbc driver for mysql in your lib. download jdbc driver jar here: http://dev.mysql.com/downloads/connector/j/

        K Offline
        K Offline
        khurram_shahzad
        wrote on last edited by
        #3

        Ok Thanks you ver much ....... Problem solved by adding MySQL.jar to Library. THanks a lot ...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups