Reputation: 3
I am trying to set up the connection with MySQL in Eclipse. I have tried the following -
After trying all the above, still I am not able to set up the connection. I keep getting the following error -
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/sampledb
Here is my code -
public class Main {
private static final String USERNAME = "user1";
private static final String PASSWORD = "user1";
private static final String CONN_STRING =
"jdbc:mysql://localhost/sampledb";
public static void main(String[] args) throws SQLException {
Connection conn = null;
try {
conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
System.out.println("Connected");
} catch (SQLException e) {
System.err.println(e);
} finally {
if (conn != null) {
conn.close();
}
}
I have seen multiple posts on this issue and I have tried all of the suggestions. I am new to Java and trying to get a hands on Java and JDBC, but I am stuck with it for last 2 days. Can someone please guide me with this issue?
Upvotes: 0
Views: 928
Reputation: 36
Did you try registering your Driver? And check if your driver is proper.
Class.forName("com.mysql.jdbc.Driver");
conn = (Connection) DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
Upvotes: 2