java - Trying to use Button to insert TextField into database -
i trying use button insert multiple textfield's database. able insert raw strings database via: have made few changes after suggestions.
public class dataentry extends mysqlclass { static label jnaam = new label("naam"); static textfield lnaam = new textfield(30); static label jemail =new label("e-mail"); static textfield lemail=new textfield(30); static label jadres =new label("adres"); static textfield ladres =new textfield(30); static label jplaats =new label("plaats"); static textfield lplaats =new textfield(100); static label jpostcode =new label("postcode"); static textfield lpostcode =new textfield(6); static label jtelefoon =new label("telefoon");static textfield ltelefoon =new textfield(13); static label jbedrijfsnaam =new label("bedrijfsnaam"); static textfield lbedrijfsnaam =new textfield(30); public static void main(string[] args) throws exception { frame frm=new frame("dataentry frame"); label lbl = new label("please fill blank:"); frm.add(lbl); frm.setsize(850, 500); frm.setvisible(true); frm.addwindowlistener(new windowadapter(){ public void windowclosing(windowevent e){ system.exit(0); } }); panel p = new panel(); panel p1 = new panel(); p.setlayout(new gridlayout(100,1)); p.add(jnaam); p.add(lnaam); p.add(jemail); p.add(lemail); p.add(jadres); p.add(ladres); p.add(jplaats); p.add(lplaats); p.add(jpostcode); p.add(lpostcode); p.add(jtelefoon); p.add(ltelefoon); p.add(jbedrijfsnaam); p.add(lbedrijfsnaam); // button submit=new button("save"); //p.add(submit); p1.add(p); frm.add(p1,borderlayout.north); button submit = new button("save"); p.add(submit); submit.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { pushdata(); } }); } public static void pushdata() { try { preparedstatement.setstring(1, lnaam.gettext()); preparedstatement.setstring(2, lemail.gettext()); preparedstatement.setstring(3, ladres.gettext()); preparedstatement.setstring(4, lplaats.gettext()); preparedstatement.setstring(5, lpostcode.gettext()); preparedstatement.setstring(6, ltelefoon.gettext()); preparedstatement.setstring(7, lbedrijfsnaam.gettext()); preparedstatement.executeupdate(); } catch (sqlexception e) { e.printstacktrace(); } } }
http://i.imgur.com/u380tp3.jpg
this new error receiving:
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception @ dataentry.pushdata(dataentry.java:66) @ dataentry$2.actionperformed(dataentry.java:58) @ java.awt.button.processactionevent(unknown source) @ java.awt.button.processevent(unknown source) @ java.awt.component.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$200(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source)
i've began write, i'll post (i'm not creating gui here, labels , textfields)
class stackoverflow { preparedstatement preparedstatement; label jnaam; textfield lnaam; label jemail; textfield lemail; label jadres; textfield ladres; label jplaats; textfield lplaats; label jpostcode; textfield lpostcode; label jtelefoon; textfield ltelefoon; label jbedrijfsnaam; textfield lbedrijfsnaam; public stackoverflow() { initgui(); } private void initgui() { jnaam = new label("naam"); lnaam = new textfield(30); jemail = new label("e-mail"); lemail = new textfield(30); jadres = new label("adres"); ladres = new textfield(30); jplaats = new label("plaats"); lplaats = new textfield(100); jpostcode = new label("postcode"); lpostcode = new textfield(6); jtelefoon = new label("telefoon"); ltelefoon = new textfield(13); jbedrijfsnaam = new label("bedrijfsnaam"); lbedrijfsnaam = new textfield(30); jbutton save = new jbutton("save"); save.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { pushdata(); } }); } private void pushdata() { try { preparedstatement.setstring(1, lnaam.gettext()); preparedstatement.setstring(2, lemail.gettext()); preparedstatement.setstring(3, ladres.gettext()); preparedstatement.setstring(4, lplaats.gettext()); preparedstatement.setstring(5, lpostcode.gettext()); preparedstatement.setstring(6, ltelefoon.gettext()); preparedstatement.setstring(7, lbedrijfsnaam.gettext()); preparedstatement.executeupdate(); } catch (sqlexception e) { e.printstacktrace(); } }
}
Comments
Post a Comment