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;
}
}
Asked
Active
Viewed 154 times
0

seenukarthi
- 8,241
- 10
- 47
- 68

Ritika Mukherjee
- 1
- 1
-
How are you running the application? Are you using any IDE? If so which one? – seenukarthi Apr 22 '22 at 05:39
-
`String user="root";` Not related to the issue, but it's never a good idea to use the "root" account. Create a new user and assign whatever limited permissions are needed. – SOS Apr 22 '22 at 05:58
1 Answers
0
Make sure the driver's JAR file is in your classpath. The Exception is telling you that Java can't find the class you're wanting to instantiate.
If it's not in 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.

AminM
- 822
- 4
- 11