Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to add a new employee to my databse??

Posted on 2002-04-06
7
Medium Priority
?
179 Views
Last Modified: 2010-03-31
i'm connecting to access 2000, and i want to add a new record to the database that is can be intered from a form
i mean the user fill in the required texts and then those texts well be added to the database.

suppose u have this code how to modify it .
==============

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class HireDate extends HttpServlet {
  public void doPost(HttpServletRequest req, HttpServletResponse res)
                                     throws ServletException, IOException {
 
         Connection con = null;          
         boolean logged = false;
         res.setContentType("text/html");
         PrintWriter out=res.getWriter();
         out.println("<HTML>");
         out.println("<HEAD><TITLE>Employee Hire Date</TITLE></HEAD>");
         out.println("<BODY BGCOLOR=\"#FFFFF\">");
         out.println("<CENTER>");
         out.println("<BR><BR>");
       try {
       
            String strSQL,strSQL1, Date1=null,Date2=null;
            ResultSet rs=null, rs1=null;
            Statement stmt;
           
            // get parameters passed from html
            Date1 = req.getParameter("date1");
         Date2 = req.getParameter("date2");      
            Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
            con = DriverManager.getConnection("jdbc:odbc:db1");
            stmt = con.createStatement();
               
            strSQL = "select * from Training" +
                 " where startdate between" + "{d 'date1'} and" + " {d 'date2'} " + " Order by Startdate ";
            rs = stmt.executeQuery(strSQL);
               
               
               
            out.println("<TABLE CELLSPACING=\"0\" CELLPADDING=\"6\" BORDER=\"1\" BGCOLOR=#C0FFFF>");                                                                              
            out.println("<TR><TD>EmpNO.</TD><TD>Course Name</TD><TD>Start Date</TD><TD>End Date</TD><TD>Place</TD></TR>");      
           
                while(rs.next())                                                      
         {                                                                      
            out.println("<TR>");                                                              
            out.println("<TD BGCOLOR=#FFDAB9>" + rs.getString("EmpNO") + "</TD>");              
            out.println("<TD BGCOLOR=#FFC0CB>" + rs.getString("Coursename") + "</TD>");
             out.println("<TD BGCOLOR=#D8BFD8>" + rs.getString("Startdate") + "</TD>");
            out.println("<TD BGCOLOR=#EEE8AA>" + rs.getString("Enddate") + "</TD>");
            out.println("<TD BGCOLOR=#FFE4C4>" + rs.getString("Place") + "</TD>");
            out.println("</TR>");                                              
        }                                    
              rs.close();
              stmt.close();

       } catch (Exception e)
         {
           e.printStackTrace();
       }
         finally
         {
            if (con != null)
               {
                 try
                     {
                      con.close();
                 } catch (SQLException se) {
                      se.printStackTrace(System.err);
                 }
            }
       }
       out.println("</CENTER>");                                                
       out.println("</BODY>");                                                  
       out.println("</HTML>");  
  }    

}
0
Comment
Question by:star5
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:jose_tijo
ID: 6924586
Hi
   Using request.getParameter("<fieldname>") you will get the values to the page.

Then you can use those values in your insert statement. These things should be done in doPost() or doGet() method depending on the submission method.

Tijo Jose
0
 

Author Comment

by:star5
ID: 6930461
whats the difference between dopost and doget , and how can i know which one i should use??
0
 
LVL 1

Expert Comment

by:jose_tijo
ID: 6930494
hi
  If the html submission method is post you should use doPost() method otherwise you should use doGet() method.

Tijo
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:star5
ID: 6930511
whats the difference between dopost and doget , and how can i know which one i should use??
0
 

Author Comment

by:star5
ID: 6930607
whats the difference between dopost and doget , and how can i know which one i should use??
0
 
LVL 1

Expert Comment

by:jose_tijo
ID: 6930609
hi
 If the html submission method is post you should use doPost() method otherwise you should use doGet()
method.

Tijo
0
 
LVL 1

Accepted Solution

by:
jose_tijo earned 60 total points
ID: 6930619
Hi
  get method will append all the form data in the url itself. also there will be a limit on size of data that is submitted in get.

In post you wont see the values in the url that are being submitted. also there is no limit on the size of data being send.

You have to use doGet() for get submission and doPost() for post submission

Tijo
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question