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.