insert data using drop down box in java into database postgresql

insert data using drop down box in java into database postgresql

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>
    &nbsp;&nbsp;&nbsp;      Subject:- Communication of Pension without medical examination.
   <br>
   <br>
   Sir,
   <br>
   <br>
   <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;*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>&nbsp;&nbsp;&nbsp;#8. Disturbing authority from which pension is to be drawn after retirement</b>
    </td>
</tr>
<tr>
    <td width=45%>
        <b>&nbsp;&nbsp;&nbsp;#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>&nbsp;&nbsp;&nbsp;#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>&nbsp;&nbsp;&nbsp;#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>&nbsp;&nbsp;&nbsp;(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>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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> 
        &nbsp;&nbsp;&nbsp;&nbsp; 
        <input type=submit name=Frm5iPrint value=Print>
    </th>
</tr>

</table>
</form>
</body>
</html>
View Answers









Related Tutorials/Questions & Answers:
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... 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
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... 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
Advertisements
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... 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
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... 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
How to insert multiple drop down list data in single column in sql database using servlet
How to insert multiple drop down list data in single column in sql database using servlet  i want to insert date of birth of user by using separate drop down list box for year,month and day into dateofbirth column in sql server
retrive the data from access database to drop down list box in jsp
retrive the data from access database to drop down list box in jsp  hai, im new to jsp now im using the jsp along with access database.in table i load all the data's i need to retrive the data from database to dropdown list box
view data from database using drop down list
view data from database using drop down list  hi i want to view the data from database by selecting a value in a drop down list. for an example drop down list have picture element.when click it select pictures from the database
store values of drop down list box in database
store values of drop down list box in database  how to store values of drop down list box in oracle database in jsp?I have information inserting form where i have date of birth as drop down list box
how to import values from database to the drop down box
how to import values from database to the drop down box   hi iam... employee page i kept a drop down box for employee Ids i want all employee IDs will display in the drop down box please help me with the code
retrieving data in to the dropdown box from postgresql database in core java
retrieving data in to the dropdown box from postgresql database in core java  hi., i just need to correct my codes.somebody help me to clear... database: import java.sql.*; import java.awt.*; import javax.swing.*; import
insert data in the database using checkbox
insert data in the database using checkbox  i am fetching data from the database using servlet on the jsp page and there is checkbox corresponding... should i insert only checked data into database on submission.   We
Drop Down Box
Drop Down Box  In a Drop Down box I want to show the user All the Country In the World. And when he type A-z,then each of the type Show those country which start with those word. Like I For-India
dynamic drop down list box - Java Beginners
dynamic drop down list box  hi all , I want to dynamically populate a drop down box from an sql query in a servlet program, using only html... servlet comes under server side code. if not using servlet store the all data
jsp code for a drop down box to retrive value from database
jsp code for a drop down box to retrive value from database  my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q   1)login.jsp: <html> <script>
drop down box - JSP-Servlet
drop down box  when i enter some letter in the input box,the corresponding words of that particular letter must be displayed below as a list from the data base in the same input box as drop down. Thanks&Regards, VijayaBabu.M
Problem insert data into database using servlet n javabean - Java Beginners
Problem insert data into database using servlet n javabean  I created a servlet for registration proses I got a problem compiling my servlet... = conn.createStatement(); rs = stmt.executeUpdate("INSERT INTO login(name,userid
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
how to store multiple values from drop down in database where i am using java struts 1.3
how to store multiple values from drop down in database where i am using java struts 1.3  hii, i am coding a form where i need a keyskills attribute... is displaying.. i need code in java so that it takes multiple values
Insert excel file data into database Using Java Programming
Insert excel file data into database in Java Program In this PHP tutorial section, you will learn how to insert excel file data into the database. We have... excel file data into Database Using java programming: import java.io.
how to insert data in database using html+jsp
how to insert data in database using html+jsp  anyone know what... and database name. Here machine name id localhost and database name..."; // declare a connection by using Connection interface
The code for retrieving data from database into Drop Down List.
The code for retrieving data from database into Drop Down List.  <% DataSource data = new MysqlDataSource(); Connection con = data.getConnection("root","system"); System.out.println("Connected
Populate a combo box using data from a database
Populate a combo box using data from a database  Hi Guys, In need... to the client using ajax, and then populate the combo box, I must'nt reload... combo box which will then load the next combo box values, now i know how
i need program to insert data in database using javascript
i need program to insert data in database using javascript  please help me
using ajax i want to insert data into oracle database
using ajax i want to insert data into oracle database  i would like to insert/update/select/delete from jsp to oracle database using ajax? please send a code for this iam using oracl database thank you
how to make drop down list in JSF & fetch data Item from database
how to make drop down list in JSF & fetch data Item from database  how to make drop down list in JSF & fetch data Item from database
how to insert data from database using oops concepts - Development process
how to insert data from database using oops concepts  Hi, How to insert data from database using oops based concepts.please write the code... the following code: import java.sql.*; class Insert{ public static String url
How to insert data from textfields into database using hibernate?
How to insert data from textfields into database using hibernate?   try{ Session session = HibernateUtil.getSessionFactory().openSession...); System.out.println("Successfully data insert in database"); tx.commit
dependent drop down box - JSP-Servlet
dependent drop down box  haloo sir Please give me the solution how to extract data from dependent drop down box with page refresh..., we have used following database tables: 1)book CREATE TABLE `book
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 Insert Data Delete Data ThanksADS_TO_REPLACE_2
How to send the data selected from drop down menu from html page to sql 2005 database.
How to send the data selected from drop down menu from html page to sql 2005... by user from html drop down menu such as check-in date for hotel reservation system ,how can I save these data in database and how to retrieve later .Thanks
creation of drop down menu using ajax in java - Ajax
creation of drop down menu using ajax in java  Hi, Here I want to create a drop down menu using ajax in ofbiz framework. I want to fetch the data from database.I got examples using asp.net and php but I am not getting
insert data into database
insert data into database  hi,thanks for reply just i am doing... and studentmaster is the database table name. i am using same details. Now give the data into the jsp page that data stored into the database.Here the error
Insert data in mysql database through jsp using prepared statement
Insert data in mysql database through jsp using prepared statement...; This is detailed jsp code that how to insert data into database by using prepared statement...*" %>  <HTML> <HEAD> <TITLE>insert data using
database is connected but not insert the data
database is connected but not insert the data  hi, i am getting connected to database.Retrive the data also but cannot insert the data into database. i am using msaccess2007.my inserstudententry.jsp code is follows,pls help me
Drop down list from database
Drop down list from database  Hi, Can I know how do we get the drop down list from database? Eg: select country--select state--select district--so..., we have created two database tables: CREATE TABLE `country
Acees data from database using combo box - JSP-Servlet
Acees data from database using combo box  please let me how i access the data from database when i select combo box combo2 having values Arts, Commerce, Science. this combo box will appear when first combo box class_name having
Display related data in other drop down list on selecting one data in one drop down list
Display related data in other drop down list on selecting one data in one drop down list  How to display related datas in dropdown list from database on selecting one data in previous dropdownlist in Java Server Page
want to insert values in drop down menu in struts1.3
want to insert values in drop down menu in struts1.3  I am using DynaValidatorForm.please help me with inserting values in color drop down menu. I have tried belowwith arraylist but was not able to find solution. add.jspx
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.  The code for retrieving data from database into Drop Down List. <% DataSource data = new
Drop Down
Drop Down  How to insert date into database using dropdown like facebook
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
callable statement,stored procedure for insert data and also for update data into oracle database using jsp  iam a fresher newbie to softparsing i... procedure for inserting data into oracle database as bind variable and same
data should not repeat in the drop down list when it is loading dynamically from database
data should not repeat in the drop down list when it is loading dynamically... the data dynamically for database but my problem is in the list the same...); } %> Data base tables are dept CREATE TABLE `dept
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from... box in javascript when elements retrieving from database.. That is whenever I insert new course in a table.. It should be seen in my list box..ADS
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  hi all, how can i insert elements into java script list box retrieving from Database. whenever I insert any element in the Db
How to insert dynamic textbox values into database using Java?
How to insert dynamic textbox values into database using Java?  Hi I am trying to insert dynamic textbox values to database, my jsp form have 2... of dynamic textboxes with Name and Address will display....Now I want to Insert
insert date into database using jsf
insert date into database using jsf  Hello I need a simple example of source code to insert a date into a database using jsf what do I have to put in backing bean and page jsf ( i need juste a date ) thanks

Ads