0

I have created a login screen but each time I test it, I get the following error message: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I know my database connection coding is correct because I have used it before and no errors are displayed. I tried adding the database driver through this Stack Overflow How to connect NetBeans to MySQL database? but the problem persists and I have also ensured the database was connected in the driver.

How do I get the driver to work?

Community
  • 1
  • 1
Osiris93
  • 189
  • 1
  • 12
  • Are you saying you want to browse the database through Netbeans or that the code you're running through Netbeans isn't connecting to the database? – Paul Oct 07 '15 at 18:17
  • The code running through Netbeans isn't connecting to the database but the issue seems to lie in the driver. – Osiris93 Oct 07 '15 at 18:20
  • The issue isn't in the driver; it's that the driver is missing. You didn't say how you're building and running your code, or how you're managing your dependencies (i.e. libraries) so this may or may not be helpful but it's on the right path: http://stackoverflow.com/questions/5893349/java-how-to-add-library-files-in-netbeans The question you linked to above is for a different problem than yours. – Paul Oct 07 '15 at 18:24
  • I just tried what you suggested and it still hasn't fixed the problem. I still get the same error. – Osiris93 Oct 07 '15 at 18:45
  • I managed to get it working. I answered my question below – Osiris93 Oct 07 '15 at 19:32
  • Disregard that, it still does not work – Osiris93 Oct 07 '15 at 20:18

2 Answers2

1

Use Connection Properties button and add a property with field name serverTimezone and value UTC.

This should work if error was caused by timezone issue.

It worked for me on Netbeans 11.2 with jdbc driver jar 8.0.17

Adi
  • 11
  • 4
0

You need to download the MySql connector/J driver. It is essentially a jar file that looks something like this: mysql-connector-java-5.1.23-bin.jar Download here: http://dev.mysql.com/downloads/connector/j/

If you are building a dynamic web application, you need to put the jar file under the WEB-INF/lib folder.

If you are building a simple Java program, add this jar to your runtime build path. Regardless of what IDE you are using, adding jar file to your build path should be pretty easy.

Hope it helps.

Minjun Yu
  • 3,218
  • 4
  • 21
  • 36