Rajesh Sitaula Rajesh Sitaula - 1 year ago 83
SQL Question

JDBC connection MSQL error "No suitable driver found"

java.sql.SQLException: No suitable driver found for jdbc:mysql@localhost:3306:emp
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.jdbd.connection.ConnectionDemo.main(ConnectionDemo.java:13)

here is my code

package com.jdbd.connection;

import java.sql.*;

public class ConnectionDemo {

public static void main(String[] args) {
// TODO Auto-generated method stub

//1. get a connection to database

Connection myconn = DriverManager.getConnection("jdbc:mysql@localhost:3306:emp","root","Dreamliner787");
//2.create a statement
Statement mystm =myconn.createStatement();
//3. Execute sql query
ResultSet myRs = mystm.executeQuery("select*from employee");
//4. process the result set
System.out.println(myRs.getString("last")+ "," + myRs.getString("first"));


catch(Exception e){



Answer Source

The error is either because your URL is wrong, or the JDBC driver is missing.

A JDBC URL typically looks like this jdbc:mysql://localhost:3306/mysql. I'm not sure why you have an @ in there. But that probably is the problem.

You can pinpoint if the problem is in the classpath by loading the driver like this.



The Class.forName isn't JDBC specific. It's simply loading the Driver class into the current class loader. Nothing related to databases there.

Prior to JDBC 4.0 you had to initialize the driver this way. I guess since this worked, you must be using a lesser version.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download