Ask Your Question

When attempting to access information through servlets from a form, I received the error message "java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver".

asked 2021-08-26 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-10-14 12:00:00 +0000

djk gravatar image

This error message indicates that the JDBC driver for MySQL is not found in the classpath of your servlet application. You need to add the MySQL JDBC driver jar file to your classpath in order to access the MySQL database.

Here are the steps to fix this error:

  1. Download the latest version of the MySQL JDBC driver from the MySQL website.
  2. Copy the JDBC driver jar file to a location in your project directory, such as the lib folder.
  3. Add the JDBC driver jar file to the classpath of your servlet application. You can do this by adding the following line to the CLASSPATH environment variable:


where "/path/to" is the directory where you have stored the MySQL JDBC driver jar file.

Alternatively, if you are using an IDE such as Eclipse or NetBeans, you can add the JDBC driver jar file to your project's build path by:

  1. Right-clicking on your project and selecting "Properties" or "Build Path".
  2. Click on "Library" or "Add JARs".
  3. Browse to the location where you saved the MySQL JDBC driver jar file and add it to your project's build path.

Once you have added the MySQL JDBC driver to your classpath, you should be able to access the MySQL database from your servlets without any errors.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2021-08-26 11:00:00 +0000

Seen: 14 times

Last updated: Oct 14 '22