I am trying to connect to a MySQL 5.5 database as follows:
public void getCon() throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("localhost/buddhiedgeserver_db","root","amma");
System.out.println("Connection"+con);
}
However, it is throwing an exception
java.sql.SQLException: No suitable driver found for localhost/buddhiedgeserver_db.
How is this caused and how can I solve it? I am using MyEclipse version 9.1 and I have included the mysql.jar in the classpath.
This means that the JDBC URL is not accepted by any of the loaded drivers as per the
Driver#acceptsURL()contract.You’ve correctly loaded the MySQL JDBC driver and it has not thrown a
ClassNotFoundException, so that part is fine. However, your JDBC URL is completely wrong. It does not conform any syntax as specified in MySQL JDBC driver documentation. Here’s a cite of relevance:Your JDBC URL of
localhost/buddhiedgeserver_dbdoes absolutely not match the documented MySQL JDBC URL format. Fix it accordingly.