sql - Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException when running external method -
sql - Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException when running external method -
background:- im trying run update query alter boolean value 0 1 if meets criteria i.e. row matches registration number of vehicle , task set open i.e. boolean 0. to enable close task in database 1 time complete
i calling method "ambulance_gui" class in "taskquery" class , query works fine in sql. have got work "frankenstein" method in java pragram compiler saying uncompilable code though working hence re-writing it.
however, getting nullpointerexception error , cannot see doing wrong, maybe because have been staring @ long cannot them working! apologise if stupid help great!
this method call:
private void jbutton4actionperformed(java.awt.event.actionevent evt) { taskqueryclass ntq2 = new taskqueryclass(this.vehiclereg); ntq2.updatetaskstatus1();
and method in taskquery class:
public void updatetaskstatus1() //throws sqlexception { seek { databaseconnection db = new databaseconnection(); stmt = conn.createstatement(); string newquery= "update task\n" + "set taskclosed='1', taskcloseddate=convert (date, sysdatetime())\n" + "from vehicle v\n" + "join task t\n" + "on v.taskid = t.task_id\n" + "where taskclosed = '0'\n" + "and v.vehicleregistrationnumber = '"+this.vehicleid+"'"; int rows = stmt.executeupdate(newquery); system.out.println(rows + " row updated successfully. "); } grab (sqlexception e) { system.out.println(e.tostring()); } { //closing connection //conn.close(); //stmt.close(); } }
the stack trace follows:
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception @ ambulance.project.taskqueryclass.updatetaskstatus1(taskqueryclass.java:130) @ ambulance.project.ambulance_gui.jbutton4actionperformed(ambulance_gui.java:380) @ ambulance.project.ambulance_gui.access$200(ambulance_gui.java:19) @ ambulance.project.ambulance_gui$3.actionperformed(ambulance_gui.java:110) @ javax.swing.abstractbutton.fireactionperformed(abstractbutton.java:2018) @ javax.swing.abstractbutton$handler.actionperformed(abstractbutton.java:2341) @ javax.swing.defaultbuttonmodel.fireactionperformed(defaultbuttonmodel.java:402) @ javax.swing.defaultbuttonmodel.setpressed(defaultbuttonmodel.java:259) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(basicbuttonlistener.java:252) @ java.awt.component.processmouseevent(component.java:6505) @ javax.swing.jcomponent.processmouseevent(jcomponent.java:3320) @ java.awt.component.processevent(component.java:6270) @ java.awt.container.processevent(container.java:2229) @ java.awt.component.dispatcheventimpl(component.java:4861) @ java.awt.container.dispatcheventimpl(container.java:2287) @ java.awt.component.dispatchevent(component.java:4687) @ java.awt.lightweightdispatcher.retargetmouseevent(container.java:4832) @ java.awt.lightweightdispatcher.processmouseevent(container.java:4492) @ java.awt.lightweightdispatcher.dispatchevent(container.java:4422) @ java.awt.container.dispatcheventimpl(container.java:2273) @ java.awt.window.dispatcheventimpl(window.java:2719) @ java.awt.component.dispatchevent(component.java:4687) @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:735) @ java.awt.eventqueue.access$200(eventqueue.java:103) @ java.awt.eventqueue$3.run(eventqueue.java:694) @ java.awt.eventqueue$3.run(eventqueue.java:692) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:87) @ java.awt.eventqueue$4.run(eventqueue.java:708) @ java.awt.eventqueue$4.run(eventqueue.java:706) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76) @ java.awt.eventqueue.dispatchevent(eventqueue.java:705) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:242) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:161) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:150) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:146) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:138) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:91)
it complains stmt = conn.createstatement();
line within method first of , next line highlights ntq2.updatetaskstatus1();
method call. next complains ambulance_gui constructor line goes generated code jframe.
the connection initialised so:
public class taskqueryclass { connection conn = null; resultset rs = null; preparedstatement pst = null; statement stmt = null; private final string vehicleid
java sql swing nullpointerexception
Comments
Post a Comment