Caused by: java.lang.ClassNotFoundException: com.mysql.jbdc.driver, Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException

I want to create a very simple Java desktop app that informs you a specific location is on my SQL database or not.

My SQL and UI are both fine, but when I run my Java I encountered the following two errors:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Datenbank konnte nicht verwendet werden
	at Database.verknuepfen(
	at Database.jBtnVerknuepfenActionPerformed(
	at Database$3.actionPerformed(
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
	at java.desktop/java.awt.Component.processMouseEvent(
	at java.desktop/javax.swing.JComponent.processMouseEvent(
	at java.desktop/java.awt.Component.processEvent(
	at java.desktop/java.awt.Container.processEvent(
	at java.desktop/java.awt.Component.dispatchEventImpl(
	at java.desktop/java.awt.Container.dispatchEventImpl(
	at java.desktop/java.awt.Component.dispatchEvent(
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(
	at java.desktop/java.awt.Container.dispatchEventImpl(
	at java.desktop/java.awt.Window.dispatchEventImpl(
	at java.desktop/java.awt.Component.dispatchEvent(
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(
	at java.desktop/java.awt.EventQueue$
	at java.desktop/java.awt.EventQueue$
	at java.base/ Method)
	at java.base/$JavaSecurityAccessImpl.doIntersectionPrivilege(
	at java.base/$JavaSecurityAccessImpl.doIntersectionPrivilege(
	at java.desktop/java.awt.EventQueue$
	at java.desktop/java.awt.EventQueue$
	at java.base/ Method)
	at java.base/$JavaSecurityAccessImpl.doIntersectionPrivilege(
	at java.desktop/java.awt.EventQueue.dispatchEvent(
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(
	at java.desktop/
Caused by: java.lang.ClassNotFoundException: com.mysql.jbdc.driver
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(
	at java.base/java.lang.ClassLoader.loadClass(
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(
	at Database.verknuepfen(
	... 37 more

I don’t need a solution code for this problem, but I appreciate it if any of you could point out some hints or materials or online articles I can look up at. Just so I will be able to resolve the above errors myself.

I leave my code below just for your reference.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.sql.*;
import javax.swing.*;

public class Database extends javax.swing.JFrame {
    private JLabel jLAbfahrt;
    private JTextField jTFAbfahrt;
    private JButton jBtnVerknuepfen; //kann es Bestätigen sein
    private JButton jBtnEnde;

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                Database inst = new Database();

    public Database() {

    private void initGUI(){

            this.setTitle("Reisende während der Corona-Pandemie");
                jLAbfahrt = new JLabel();
                jLAbfahrt.setText("Abfahrt von: ");
                jLAbfahrt.setBounds(12, 12, 175, 14);
                jTFAbfahrt = new JTextField();
                jTFAbfahrt.setBounds(12, 32, 111, 21);
                jTFAbfahrt.addKeyListener(new KeyAdapter() {
                    public void keyPressed(KeyEvent evt) {
                jBtnVerknuepfen = new JButton();
                jBtnVerknuepfen.setBounds(157, 32, 219, 21);
                jBtnVerknuepfen.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                jBtnEnde = new JButton();
                jBtnEnde.setBounds(208, 142, 97, 21);
                jBtnEnde.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
            this.setSize(400, 226);
        }catch (Exception e){

    private void verknuepfen(){
        try  {
            Connection verbindung = DriverManager.getConnection("jdbc:mysql://localhost:3306/neueschema", "root", "morry329A");
            System.out.println("Datenbank verwendet!");
            Statement stm = verbindung.createStatement();
            String sql = "'SELECT * FROM neueschema.Reisende WHERE Abfahrt= "+jTFAbfahrt.getText().toString()+"'";;
            ResultSet resultset = stm.executeQuery(sql);


                JOptionPane.showMessageDialog(null, "Ausgabe abgeschlossen");
            } else {
                JOptionPane.showMessageDialog(null, "Ausgabe noch nicht abgeschlossen");

        } catch (SQLException | ClassNotFoundException exp) {
            throw new IllegalStateException("Datenbank konnte nicht verwendet werden", exp);

    private void jBtnVerknuepfenActionPerformed(ActionEvent evt){

    private void jTFAbfahrtKeyPressed(KeyEvent evt){
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){

    private void jBtnEndeActionPerformed(ActionEvent evt) {

Hello there !
Have you been able to figure this out ? Based on the error and running it on my own device, I think
the driver is not found because it’s not loaded properly into your app
The way I fixed it on my device is to use a Maven project (in normal project I cannot add .jars, known bug, maybe you have that too).

After I did, I noticed some errors in your code:
You wrote jbdc which should be jdbc (Java Database Connectivity) and Driver instead of driver. Without the right classname it indeed cannot be found in the driver jar/library.
I made a simplified version of your sql String, with that I did not need ’ ’ so you might want to look into that as well.
Finally, com.mysql.jdbc.Driver is deprecated, so I ended up using this:

After this I can connect to my DB using your app.

Hello ewoutjava, thank you so much for your solution and for trying it out on your device! I truly appreciate it. Sorry for not being able to respond earlier, I was on a vacation.

I have one question. By “use a Maven project”, what exactly did you mean? Did you add Framework support to your pre-existing java project codes? Did you create a maven project from the scratch and add my code there?

EDIT: I assume that you created a maven project on your IDE editor or similar and added my code there. This way I was also able to connect to my DB without an inch.

you’re very welcome !
Yes, indeed the 2nd option, I created a Maven project from scratch. This way it’s always easy to add dependencies to the pom.xml if I need them

1 Like