Encountered java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver error, the mysql connector has been added to the reference library
P粉877114798
P粉877114798 2024-03-19 20:39:21
0
1
444

public class Connect {
    public static ResultSet select(String query) throws Exception{
        String url="jdbc:mysql://localhost:3306/ms?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
        String user="root";
        String password="Ritika@123";
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection con=DriverManager.getConnection(url, user, password);
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(query);
        rs.next();
        return rs;
    }
}

P粉877114798
P粉877114798

reply all(1)
P粉466290133

Make sure the driver's JAR file is in your classpath. This exception tells you that Java cannot find the class you want to instantiate.

If it's not on your classpath, it can't be found.

For example, you can run it on the command line like this:

java -cp ".;driver.jar" Connect

Or set the CLASSPATH variable in your environment to include the driver.jar file.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template