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";
      con = DriverManager.getConnection(url+db, user, pass);
    catch (Exception e){

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.

6 Years
Discussion Span
Last Post by khurram.1987

Did you download MySQL.jar file ?
If so is this .jar in your PATH variable or in the External Jar folder of your IDE if you use an IDE ?



No .. I didn't added MySQL.jar,
I've just created database using 'MySQL Command Line Client' and create application using netbeans IDE.
Can you please little explane about this MySQL.jar issue ... may be this was my mistake.

THANKS 'pbl'

Edited by khurram.1987: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.