I've been having a problem with mySQL database connectivity. I'm getting an error:
No suitable driver found for jdbc:mysql://127.0.0.1/sakila.
I have installed mySQL workbench, and have the driver from here http://dev.mysql.com/downloads/connector/j/
I have saved mysql-connector-java-5.1.18-bin and set the classpath to
C:\Program Files\Java\jre7\lib\mysql-connector-java-5.1.18-bin;
and started the mysql workbench where the database is found.
The code I am using is as follows: Which I am sure works, as I've asked a friend to test it form me. Unfortunately, we are developing on different platforms and could not instruct me as to how to fix this error. Has anyone an idea on how I can fix this?
public class Version {
public static void main(String[] args) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://127.0.0.1/sakila";
//String url = "jdbc:mysql://localhost:3306/sakila";
String user = "root";
String password = "root";
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
rs = st.executeQuery("select * from actor;");
System.out.println("test");
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (Exception ex) {
System.out.println(ex);
}
}
}
EDIT: Problem sovled. Did not have .jar appended to the end of the bin file, which is necessary.