Java MySQL Driver issue
-
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 errorDriver Class not found ...
at this statmentClass.forName(driver);
..... and similarly on trying this driversun.jdbc.odbc.JdbcOdbcDriver
the above mentioned statmentClass.fonName ...
executes but then it gives error on statmentcon = DriverManager.getConnection(url+db, user, pass);
error isNo 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. -
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 errorDriver Class not found ...
at this statmentClass.forName(driver);
..... and similarly on trying this driversun.jdbc.odbc.JdbcOdbcDriver
the above mentioned statmentClass.fonName ...
executes but then it gives error on statmentcon = DriverManager.getConnection(url+db, user, pass);
error isNo 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.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/
-
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/
Ok Thanks you ver much ....... Problem solved by adding MySQL.jar to Library. THanks a lot ...