Solved

how to add a new employee to my databse??

Posted on 2002-04-06
7
172 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 20 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now