I'm making a database application for a school assignment and for some reason, the application just won't connect with the mysql database. I'm using the mysql workbench, version 8+ and the connector file's version is 8.0.27. Using netbeans, I followed all the steps to make the connection but yet, in the output window, when I click the add new record or update button, it doesn't respond.
Here's the code that I think is relevant to this question
//1st excerpt
public class WarehouseDBM extends javax.swing.JFrame {
private static final String username ="root";
private static final String password ="";
private static final String dataConnection = "jdbc:mysql://localhost:3306/Warehouse_Database";
Connection sqlConnection = null;
PreparedStatement prepStat = null;
ResultSet resultSet = null;
//2nd excerpt
private void btnAddNewActionPerformed(java.awt.event.ActionEvent evt) {
try
{
Class.forName("com.mysql.cj.jdbc.driver");
sqlConnection = DriverManager.getConnection(dataConnection, username, password);
prepStat = sqlConnection.prepareStatement("Insert into Warehouse_Data ( Item_ID, Item_Name, Existing_Quantity, Quantity_Added, Quantity_Used) values"
+ "(?,?,?,?,?)");
prepStat.setString(1,txtItemId.getText());
prepStat.setString(2,txtItemName.getText());
prepStat.setString(3,txtExistingQuantity.getText());
prepStat.setString(4,txtQuantityAdded.getText());
prepStat.setString(5,txtQuantityUsed.getText());
System.out.println("Connected Successfully");
prepStat.executeUpdate();
JOptionPane.showMessageDialog(this, "Item record added");
}
catch (ClassNotFoundException | SQLException ex) {
java.util.logging.Logger.getLogger(WarehouseDBM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
Once I click the add new item button, the console shows the following error
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:377)
at warehousesterling.WarehouseDBM.btnAddNewActionPerformed(WarehouseDBM.java:269)
at warehousesterling.WarehouseDBM$4.actionPerformed(WarehouseDBM.java:206)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6614)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6379)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Also do note, I have included the jar file in the library of this application, and I still face this error. I've tried multiple solutions given on the net but to no avail. If there is anything I have missed, please do tell me.
Edit: To add it to the library i followed the following steps: Project--> right click on libraries--> add jar/folder --> selected the jar file.