I am trying to set up the connection with MySQL in Eclipse. I have tried the following -
- I have added the "my-sql-connector.jar" to the build path and class path.
- I have tried adding it in the WEB-INF.
- Tried using class.forName.
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?