Solved

how to add a new employee to my databse??

Posted on 2002-04-06
7
174 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

770 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