Insert data into mysql table using java applets -
i have been given college assignment insert data mysql table using java applets. when press submit button, command prompt throws lot of exceptions(pic attached) , no data inserted table.
following code:
//student registration form (using applets , awt controls) import java.awt.*; import java.awt.event.*; import java.applet.*; import java.sql.*; import java.util.*; public class mysql4 extends applet implements actionlistener{ label l1 = new label("roll no. : "); textfield t1 = new textfield("",10); label l2 = new label("name : "); textfield t2 = new textfield("",20); label l3 = new label("gender : "); checkboxgroup radiogroup = new checkboxgroup(); checkbox r1 = new checkbox("male", radiogroup, false); checkbox r2 = new checkbox("female", radiogroup, true); label l4 = new label("hobbies : "); checkbox c1 = new checkbox("sports"); checkbox c2 = new checkbox("cooking/gardening"); checkbox c3 = new checkbox("music"); checkbox c4 = new checkbox("arts/crafts"); label l5 = new label("course opted : "); choice l=new choice(); label l6 = new label("feedback : ",label.center); textarea ta = new textarea("",15,20); button b1 = new button("submit"); button b2 = new button("reset"); public void init() { l1.setalignment(label.center); add(l1); add(t1); add(l2); add(t2); add(l3); add(r1); add(r2); add(l4); add(c1); add(c2); add(c3); add(c4); add(l5); l.add("bca"); l.add("mca"); l.add("pgdca"); add(l); add(l6); add(ta); b1.addactionlistener(this); add(b1); b2.addactionlistener(this); add(b2); } public void actionperformed(actionevent e){ if(e.getsource()==b1){ try{ string mydriver = "com.mysql.jdbc.driver"; string myurl = "jdbc:mysql://localhost:3306/sonoo?usessl=false"; class.forname(mydriver); connection con = drivermanager.getconnection(myurl, "root", "12345678"); string query = "insert details (rollno, name, gender, hobbies, course, feedback)" + " values (?, ?, ?, ?, ?, ?)"; preparedstatement ps = con.preparestatement(query); ps.setstring (1, l1.gettext()); ps.setstring (2, l2.gettext()); checkbox chkr = radiogroup.getselectedcheckbox(); ps.setstring (3, chkr.getlabel()); checkbox chk = radiogroup.getselectedcheckbox(); ps.setstring (4, chk.getlabel()); ps.setstring (5, l.getselecteditem()); ps.setstring (6, ta.gettext()); ps.execute(); con.close(); }catch(exception ex){ ex.printstacktrace(); system.out.println(ex.getmessage()); } }else if(e.getsource()==b2){ t1.settext(" "); t2.settext(" "); r1.setstate(false); r2.setstate(true); c1.setstate(false); c2.setstate(false); c3.setstate(false); c4.setstate(false); l.select("bca"); ta.settext(" "); }else{} } }
you're getting accesscontrolexception
when driver trying read file.encoding
property. applet needs given permission driver work.
Comments
Post a Comment