I am trying to connect to a database on a WAMP server on the same device the computer is running. Below is the code from a tutorial on zetcode. I have copied it almost completely except for the SQL login details. I am getting an error, it is displayed below the code.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.sun.corba.se.impl.util.Version;
public class TestDb {
public static void main(String[] args) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/mltest";
String user = "mlcomponents";
String password = "color12";
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
rs = st.executeQuery("SELECT VERSION()");
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Version.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Version.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
}
Error message I am receiving:
May 25, 2016 3:51:28 PM TestDb main
SEVERE: No suitable driver found for jdbc:mysql://localhost:3306/mltest
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mltest
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at TestDb.main(TestDb.java:21)