0

i keep getting " No suitable driver found for jbdc:mysql://localhost:3306/db_catal".

I have put MySQL connector in the buildpath and also in lib folder of web-inf. Why am I still getting this error? Voici l'image

code :

package dao;
import java.sql.*;

public class SingletonConnection {

    private static Connection connection ;
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection=DriverManager.getConnection
                    ("jbdc:mysql://localhost:3306/db_catal","root","");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   



          }
    public static Connection getConnection() {
        return connection ;}    

    }
RamPrakash
  • 1,687
  • 3
  • 20
  • 25
Flàyn
  • 23
  • 5

1 Answers1

0

You have to register your driver first before calling the getConnection() method.

if you have already done then you have to set classpath for mysql-connectorXXXX.jar

In eclipse, use the build path.

Your program like below will compile fine but as soon as you will run it you will get the error "java.sql.SQLException: No suitable driver found for "jbdc:mysql://localhost:3306/db_catal" because of the JDBC URL format "jdbc:mysql" is not matching with any registered JDBC driver.

Read more: https://javarevisited.blogspot.com/2016/09/javasqlsqlexception-no-suitable-driver-mysql-jdbc-localhost.html#ixzz67da2aSqw

How to add jar to classPath through eclipse

  • Right click on your project
  • Select Build Path Click on Configure Build Path
  • Click on Libraries and make sure mysql jar is present
  • if not select the jar file from the required folder
  • click on order and export tab. make sure you selected all
  • Click and Apply and Ok
RamPrakash
  • 1,687
  • 3
  • 20
  • 25
  • hello thanks for answering i tried that by adding the mysql connector to the libraries from project/buildpath/Libaries/add External jar but it didnt work is that what you mean by classpath ? – Flàyn Dec 09 '19 at 19:14
  • @Flàyn I added instructions to add jar to eclipse. – RamPrakash Dec 09 '19 at 19:20
  • thx . but it dosent work still the same Image : https://postimg.cc/sMhP2jq5 – Flàyn Dec 09 '19 at 19:23
  • @Flàyn Can you try this and see if e1 is printing out ```try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e1) { e1.printStackTrace(); }``` – RamPrakash Dec 09 '19 at 19:30
  • i tried it image : https://postimg.cc/gxH1kLj6 i dont think e1 is printing out – Flàyn Dec 09 '19 at 19:39
  • replace line 9 with the try catch i shared you. – RamPrakash Dec 09 '19 at 19:45
  • i tired it and there is no e1 exception i think here is the image : https://postimg.cc/SXF3YqC0 – Flàyn Dec 09 '19 at 20:32