Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public void onEditChanged (CellEditEvent edittedCell) throws ClassNotFoundExcept

ID: 3891312 • Letter: P

Question

public void onEditChanged (CellEditEvent edittedCell) throws ClassNotFoundException{
     
        PreparedStatement pst = null;
        ResultSet rs = null;
      
        try {
           Connection conn = dbConnection.getConnection();
           //PreparedStatement stmt = conn.prepareStatement(sql);
          
          
            Object newValue = edittedCell.getNewValue();
            final String updateQuery = "UPDATE requests SET notes = ? WHERE techName = ?";
            //If you require multiple columns to get a unique row, add them in the where clause as well.
            //careate the statement and execute
            pst = conn.prepareStatement(updateQuery);
            //uniqueIdentifier which determine the unique column in the table like id
            pst.setString(1,techName.toString()); //if a string
            pst.setString(2,newValue.toString()); //if a string
            pst.execute();
            pst.close();
            conn.close();
        } catch (SQLException e) {

        }

IM AM GETTING THIS ERROR FOR ABOVE CODE:

*****************

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
   at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
   at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
   at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
   at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
   at javafx.event.Event.fireEvent(Event.java:198)
   at javafx.scene.control.TableCell.commitEdit(TableCell.java:349)
   at javafx.scene.control.cell.CellUtils.lambda$createTextField$615(CellUtils.java:248)
   at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
   at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
   at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
   at javafx.event.Event.fireEvent(Event.java:198)
   at javafx.scene.Node.fireEvent(Node.java:8413)
   at com.sun.javafx.scene.control.behavior.TextFieldBehavior.fire(TextFieldBehavior.java:179)
   at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:178)
   at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:218)
   at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callActionForEvent(TextInputControlBehavior.java:127)
   at com.sun.javafx.scene.control.behavior.BehaviorBase.lambda$new$74(BehaviorBase.java:135)
   at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
   at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
   at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
   at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
   at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
   at javafx.event.Event.fireEvent(Event.java:198)
   at javafx.scene.Scene$KeyHandler.process(Scene.java:3964)
   at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910)
   at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)
   at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501)
   at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
   at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
   at java.security.AccessController.doPrivileged(Native Method)
   at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$353(GlassViewEventHandler.java:248)
   at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
   at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
   at com.sun.glass.ui.View.handleKeyEvent(View.java:546)
   at com.sun.glass.ui.View.notifyKey(View.java:966)
   at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
   at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at sun.reflect.misc.Trampoline.invoke(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
   at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
   ... 79 more
Caused by: java.lang.NullPointerException
   at Admin.AdminController.onEditChanged(AdminController.java:287)
   ... 89 more


******************

PLEASE HELP! I am trying to save editted cell to the SQLite Db .... I am able to edit the cell but when I click Enter to have it Saved in db, it throws above error....

Explanation / Answer

As the last line in the error says Null Pointer Exception, so first of all check whether you are getting the value from the edittedCell and the connection value from dbConnection.getConnection. Check whether any of them is null.

And most importantly change the ps.execute to ps.executeUpdate() method. Changing the method will solve your problem.