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粉4662901332024-03-20 16:20:07
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.