0

I'm using Netbeans IDE 8.02 to manipulate an access database, but with the removal of the driver, I have been struggling with UCanAccess. I have been able to insert datainto the database and I have been able to receive data from the database, but I'm struggling to delete a record, even though it is a very simple query.

Here is my method:

  public void VerwyderHemp(String Path, int KledingStukNo){

    try {
        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

        conn = DriverManager.getConnection("jdbc:ucanaccess://" + Path);
        st = conn.createStatement();

        String sql = "DELETE FROM tblHemde WHERE tblHemde.ID = " + KledingStukNo + ";" ;
        ResultSet rs = st.executeQuery(sql);

        } catch (Exception e) {

            e.printStackTrace();
        }


    }

I use my method in a jButton in a jFrame, and it looks like this:

private void     jButtonVerwyderHempActionPerformed(java.awt.event.ActionEvent evt)                                                                  {                                                    
    // TODO add your handling code here:
    int KledingstukNo = Integer.parseInt(jTextFieldDeleteHemp.getText());
    myHemp.VerwyderHemp(Path2, KledingstukNo);
    System.out.println(KledingstukNo);
}

The parameter "Path2" just specifies where the database is and gives no problems, as I have used it in similar methods, but I'm not so sure about the other parameter "KledingstukNo", although when I print out "KledingstukNo", I get the value that is inputted in the "jTextFieldDeleteHemp".

When I connect to my database I receive the following message:

WARNING:Error in the metadata of the table tblHemde: table's row count in the metadata is 8 but 9 records have been found and loaded by UCanAccess. All will work fine, but it's better to repair your database.

When I try to delete a record I receive the following error message:

*

net.ucanaccess.jdbc.UcanaccessSQLException: java.lang.NullPointerException java.lang.NullPointerException
9
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:202)
    at Klasse.Hemp.VerwyderHemp(Hemp.java:196)
    at GUI.FinalGUI.jButtonVerwyderHempActionPerformed(FinalGUI.java:598)
    at GUI.FinalGUI.access$600(FinalGUI.java:27)
    at GUI.FinalGUI$7.actionPerformed(FinalGUI.java:328)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6516)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6281)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4872)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
    at java.awt.EventQueue.access$300(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:706)
    at java.awt.EventQueue$3.run(EventQueue.java:704)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:720)
    at java.awt.EventQueue$4.run(EventQueue.java:718)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.sql.SQLException: java.lang.NullPointerException java.lang.NullPointerException
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.executeQuery(Unknown Source)
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:199)
    ... 40 more
Caused by: org.hsqldb.HsqlException: java.lang.NullPointerException
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.result.Result.newErrorResult(Unknown Source)
    at org.hsqldb.StatementDMQL.execute(Unknown Source)
    at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
    at org.hsqldb.Session.executeDirectStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 43 more
Caused by: java.lang.NullPointerException
    at net.ucanaccess.jdbc.UcanaccessConnection.getCtxConnection(UcanaccessConnection.java:87)
    at net.ucanaccess.triggers.TriggerDelete.fire(TriggerDelete.java:33)
    at org.hsqldb.TriggerDef.pushPair(Unknown Source)
    at org.hsqldb.Table.fireTriggers(Unknown Source)
    at org.hsqldb.StatementDML.delete(Unknown Source)
    at org.hsqldb.StatementDML.executeDeleteStatement(Unknown Source)
    at org.hsqldb.StatementDML.getResult(Unknown Source)
    ... 47 more
BUILD SUCCESSFUL (total time: 24 seconds)*

I don't see a reason for this error, please help!

Tokolosshh
  • 11
  • 2

2 Answers2

1

It's an improper and unexpected use of the statement interface. Don't use

st.executeQuery(sql);

with a delete sql statement but st.execute(sql); or st.executeUpdate(sql);

jamadei
  • 1,700
  • 9
  • 8
1

You are not making a selection query, so you cant use st.executeQuery(sql); you must use a st.executeUpdate(); to make the delete, insert or update queries.

Kevin Alemán
  • 480
  • 6
  • 14