can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc and postgresql as data base
syntax which i m using is like:-
java class
package blog.forms; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.jar.Attributes.Name; import org.apache.wicket.extensions.yui.calendar.DateField; import org.apache.wicket.extensions.yui.calendar.DatePicker; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.DropDownChoice; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextArea; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.form.upload.FileUploadField; import org.apache.wicket.model.Model; import blog.main.Loginn; import blog.main.MainPage; public class form1a extends WebPage { //private FileUploadField upload; private Integer eid; //private Model model; final TextArea fathername = new TextArea("empfathername", new Model()); final TextArea Designation = new TextArea("empdesignation", new Model()); final TextArea name = new TextArea("empname", new Model()); **final Model model = new Model(); List officenames = new ArrayList(); DropDownChoice officename = new DropDownChoice("officename", model, officenames);** //final TextArea OfficeName = new TextArea("officename", new Model()); final TextField<java.util.Date> DOB = new TextField<java.util.Date>("BirthDate", new Model()); final TextField DOR = new TextField("RetireDate", new Model(), Date.class); final TextField PensionFraction = new TextField("pensionfraction", new Model()); final TextArea TreasuryNameAddress = new TextArea("treasurynameandaddress", new Model()); final TextArea BankNameAddress = new TextArea("banknameandaddress", new Model()); final TextField BankAccountNo = new TextField("BankAccountNo", new Model()); final TextArea AccountOffice = new TextArea("accountoffice", new Model()); final TextField Place = new TextField("place", new Model()); final TextField date = new TextField("quoteDate", new Model(), Date.class); //final TextField Signature = new TextField("sign", new Model()); final TextArea PresentAddress = new TextArea("presentpostaladdress", new Model()); final TextArea RetireAddress = new TextArea("addressafterretirement", new Model()); public form1a(Integer emp_id) { eid=emp_id; Form form = new Form("f"){ protected void onSubmit(){ String sym = (String) model.getObject(); DateFormat format=new SimpleDateFormat("dd-mmm-yyyy"); Date date = (Date) new Model().getObject(); //date = (Date)format.parse(strDate); doupdate(); setResponsePage(new MainPage(eid)); System.out.println(name.getDefaultModelObjectAsString()); } }; date.setRequired(true); date.add(new DatePicker()); DOB.setRequired(true); DOB.add(new DatePicker()); DOR.setRequired(true); DOR.add(new DatePicker()); **officenames.add("National Information Centre"); officenames.add("Ministry of Communications & Information Technology"); officename.setRequired(true); form.add(officename);** form.add(name); form.add(fathername); form.add(Designation); form.add(DOB); form.add(DOR); form.add(PensionFraction); form.add(TreasuryNameAddress); form.add(BankNameAddress); form.add(BankAccountNo); form.add(AccountOffice); form.add(Place); form.add(date); form.add(PresentAddress); form.add(RetireAddress); add(form); } private void doupdate() { //String datetext = DOB.getText(); //java.sql.Date v5 = new java.sql.Date(new java.util.Date().getTime()); // java.sql.Date v6 = new java.sql.Date(new java.util.Date().getTime()); //java.sql.Date v13 = new java.sql.Date(new java.util.Date().getTime()); String v1=name.getInput(); String v2=fathername.getInput(); String v3=Designation.getInput(); **String v4=officename.getInput();** java.util.Date DOB1 = new java.util.Date(); String v5 =DOB.getInput(); SimpleDateFormat sd = new SimpleDateFormat("dd/mm/yyyy"); java.util.Date DOR1 = new java.util.Date(); String v6 =DOR.getInput(); SimpleDateFormat sd1 = new SimpleDateFormat("dd/mm/yyyy"); //java.sql.Date sqlDate = new java.sql.Date(DOB1.getTime()); // Date v5 =java.sql.Date.valueOf(DOB.getInput()); Integer v7=Integer.parseInt(PensionFraction.getInput()); String v8=TreasuryNameAddress.getInput(); String v9=BankNameAddress.getInput(); Integer v10=Integer.parseInt(BankAccountNo.getInput()); String v11=AccountOffice.getInput(); String v12=Place.getInput(); java.util.Date date1 = new java.util.Date(); String v13 =date.getInput(); SimpleDateFormat sd2 = new SimpleDateFormat("dd/mm/yyyy"); String v15 = PresentAddress.getInput(); String v16 = RetireAddress.getInput(); try { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/pension/form1a", "postgres", "postgres"); // String emp_id = l.getUname(); String sql="update form1a SET name=?,fathername=?,designation=?,officename=?,dob=?,dor=?,pf=?,treasury=?,banknameadd=?,bankaccno=?,acc_office=?,place=?,date=?,paddress=?,raddress=? WHERE emp_id='"+eid+"'"; PreparedStatement prest = conn.prepareStatement(sql); DOB1 = sd.parse(v5); DOR1 = sd1.parse(v6); date1= sd2.parse(v13); /*Statement st=conn.createStatement(); ResultSet rs=st.executeQuery("select name from form1a where emp_id='"+emp_id+"'"); if(rs == null) {*/ //String sql="insert into form1a values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; java.sql.PreparedStatement pst = conn.prepareStatement(sql); pst.setString(1, v1); pst.setString(2, v2); pst.setString(3, v3); **pst.setString(4, v4);** //pst.setDate(5,new java.sql.Date( DOB1)); pst.setDate(5, new Date(DOB1.getTime())); pst.setDate(6,new Date(DOR1.getTime())); pst.setInt(7, v7); pst.setString(8, v8); pst.setString(9, v9); pst.setInt(10, v10); pst.setString(11, v11); pst.setString(12, v12); pst.setDate(13,new Date(date1.getTime())); pst.setString(14, v15); pst.setString(15, v16); pst.executeUpdate(); pst.close(); } catch(Exception e){ throw new RuntimeException(e); } } } **HTML code of it:-** <html xmlns:wicket="..."> <head><title>Form 1-A</title> <link rel="stylesheet" type="text/css" href="css/Log.css"> </head> <body topmargin='0' leftmargin='0' rightmargin='0' bgcolor='white' onload="scroll()"> <form wicket:id="f"> <table border='1' width='80%' cellspacing='2' cellpadding='6' align='center'> <tr> <th colspan='4' bgcolor='#0e1f5b'> <font size=3 color="#FFFFFF"> <u>FORM 1-a</u> <br> FORM OF APPLICATION COMMUNICATION OF AFRACTION OF SUPPERANNUATION PENSION WITHOUT MEDICAL EXAMINATION WHEN APPLICANT DESIRES THAT THE PAYMENT OF THE COMMUTED VALUE OF PENSION SHOULD BE AUTHORISED THROUGH THE PENSION PAYMENT ORDER. </font> <br> <font size=2 color="yellow"> [See Rules 5(2), 12, 13 (3), 14 (1) and 15(3)] <br> (To be submitted in duplicate at least three months before the date of retirement) </font> </th> </tr> <tr> <th colspan='4' bgcolor='white' align='left'> <font size=2 color="black"> <br> <br> The Head of Office, <br> Ministry of Communication & Information Technology, <br> Department of Information Technology, <br> National Informatics Centre, <br> A-Block, C.G.O. complex, <br> Lodi Road, New Delhi - 110 003. <br> <br> Subject:- Communication of Pension without medical examination. <br> <br> Sir, <br> <br> <br> I desire to commute a fraction of my pension in accordance with the provision of the Central Civil Services Commutation of Pension Rules,1981. The necessary particulars are furnished below: </font> </th> </tr> <tr> <td width=45% > <b> 1.Name (in BLOCK letters)</b> </td> <td width=55%> <textarea wicket:id="empname" cols='50' class='normal' name='empfathername'></textarea> </td> </tr> <tr> <td width=45%> <b> 2.Father'sname (and also husband's name in the case of a female Govt. servant)</b> </td> <td width=55%> <textarea wicket:id="empfathername" cols='50' class='normal' name='empfathername'></textarea> </td> </tr> <tr> <td width=45%> <b> 3.Designation</b> </td> <td width=55%> <textarea wicket:id="empdesignation" cols='50' class='normal' name='empdesignation'></textarea> </td> </tr> **<tr> <td width=45%> <b> 4.Name of Office/Department/Ministry in which employed</b> </td> <td width=55%> <select wicket:id="officename"> <option>National Informatics Centre</option> <option>Ministry of Communications & Information Technology</option> </select> </td> </tr>** <tr> <td width=45%> <b> 5.Date of Birth (by Christian era)</b> </td> <td width=55%> <input type="text" wicket:id="BirthDate"> </td> </tr> <tr> <td width=45%> <b> 6.Date of Retirement on superannuation or on the expiry of extension in service granted under FR 56(d).</b> </td> <td width=55%> <input type="text" wicket:id="RetireDate"> </td> </tr> <tr> <td width=45%> <b> *7.Fraction of superannuation pension proposed to be commuted</b> </td> <td width=55%> <input type=text wicket:id="pensionfraction"/> </td> </tr> <tr> <td colspan="2"> <b> #8. Disturbing authority from which pension is to be drawn after retirement</b> </td> </tr> <tr> <td width=45%> <b> #8(a).Treasury/Sub-Treasury (Name and complete address of the Treasury/Sub-Treasury to be indicated)</b> </td> <td width=55%> <textarea wicket:id="treasurynameandaddress" rows='2' cols='50' class='normal' name='treasurynameandaddress'></textarea> </td> </tr> <tr> <td width=45%> <b> #8(b.i).Branch of the nominated nationalised bank with complete postal address</b> </td> <td width=55%> <textarea wicket:id="banknameandaddress" rows='2' cols='50' class='normal' name='BankNameandAddress'></textarea> </td> </tr> <tr> <td width=45%> <b> #8(b.ii).Bank Account No. to which monthly pension is to be credited each month.</b> </td> <td width=55%> <input type=text wicket:id="BankAccountNo"/> </td> </tr> <tr> <td width=45%> <b> (c).Account Office of the Ministry/Department/Office</b> </td> <td width=55%> <textarea wicket:id="accountoffice" rows='2' cols='50' class='normal' name='AccountOffice'></textarea> </td> </tr> <tr> <td width=45%> <b>Place:-</b> <input type=text wicket:id="place"/> <br> <b>Date:-</b> <input type="text" wicket:id="quoteDate"> </td> <td width=45%> <b>Signature:-</b> <br> <br> <br> <b>Present Postal address</b> <br> <textarea wicket:id="presentpostaladdress" rows='2' cols='50' class=normal name='PresentPostalAddress'></textarea> <br> <b>Postal Address after retirement</b> <br> <textarea wicket:id="addressafterretirement" rows='2' cols='50' class=normal name=AddressAfterRetirement></textarea> </td> </tr> <tr bgcolor="#0e1f5b" height=30> <th colspan=4> <input type=submit name=Frm5iSave value=Save> <input type=submit name=Frm5iPrint value=Print> </th> </tr> </table> </form> </body> </html>
Ads