-1
import java.sql.*;

class Mysqll{
    public static void main(String args[]){
        try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc::mysql://localhost:3306/asd","root","qwerty");
        Statement st = con.createStatement();

        ResultSet rs = st.executeQuery("select * from abc");

        while(rs.next())
        {
            System.out.println(rs.getInt(1) + "   " + rs.getString(2));
        }
        con.close();
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}

I am new to jdbc programming. So plese help. Getting this Exception while running the program.

java.sql.SQLException: No suitable driver found for jdbc::mysql://localhost:3306/asd

I had copied mysql-connector.jar file into jre/lib/ext folder. Thanx in advance.

1 Answers1

0

The connection string being passed to DriverManager is a URL. The formatting matters, and your problem is due to an extra colon between jdbc and mysql (verified by testing on my own system).

Replace jdbc::mysql: with jdbc:mysql:.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
dcsohl
  • 7,186
  • 1
  • 26
  • 44