SERVLET

SERVLET

package employmaster;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EmployeeMastAddDetails extends HttpServlet
    {


        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
        {
            String userId=new String("");
            ResultSet rs = null;
            Connection conn = null;
            RequestDispatcher rd=null;

            try 
                {


                response.setContentType("text/html");
                PrintWriter out=response.getWriter();
                String user_id=request.getParameter("empID");
                String user_name=request.getParameter("empName");
                String user_dob=request.getParameter("empDob");
                String user_gender=request.getParameter("empGender");
                String user_designationCode=request.getParameter("empDesignationCode");
                String user_CdacId=request.getParameter("empCdacId");
                String user_deptId=request.getParameter("empdeptId");
                String user_CdacEmailId=request.getParameter("empCdacEmailId");
                String user_otheremailId=request.getParameter("empotherEmailId");
                String user_contactNo=request.getParameter("empContactNo");
                String user_emergencyNo=request.getParameter("empEmergencyNo");
                String user_localAdd=request.getParameter("empLocalAddress");
                String user_Permanentadd=request.getParameter("empPermanentAddress");
                String user_Qualification=request.getParameter("empQulification");
                String user_Anniversary=request.getParameter("empAnniversaryDate");
                String user_JoiningDate=request.getParameter("empJoiningDate");
                String user_RelievingDate=request.getParameter("empRelievingdate");
                String user_IpAdd=request.getParameter("empIpAddress");
                String user_SystemDetail=request.getParameter("empSystemDetails");
                String user_IsActive=request.getParameter("empIsActive");
                String user_UserType=request.getParameter("empUserType");
                String user_password=request.getParameter("empPassword");


            String sql1="select PMSNUM_EMP_ID from PMST_EMP_MST where PMSNUM_EMP_ID="+user_id;
            conn=EmployeeMastConnection.getConnection();
            Statement st=conn.createStatement();
            st.executeQuery(sql1);
            rs = st.getResultSet();
              while (rs.next ()){
              userId=rs.getString("PMSNUM_EMP_ID");

              }

              if(userId.equals(user_id))
              {
                  out.println("Emp_Id is already exist");
                  rd=request.getRequestDispatcher("/employmaster/EmployeeMstAdd.jsp");


              }

              else
              {


                  int id=Integer.parseInt(userId);
                  if(rs.last()){
                  id=id+1;
                  userId=new Integer(id).toString();
                  }
                  String sql=" Insert into PMST_EMP_MST(PMSNUM_EMP_ID,PMSSTR_EMP_NAME,PMSDT_DOB_DATE,PMSSTR_GENDER,PMSNUM_DESIGNATION_CODE," +
                    "PMSNUM_CDAC_EMPID,PMSNUM_DEPARTMENT_ID,PMSSTR_CDAC_EMAILID,PMSSTR_OTHER_EMAILID,PMSNUM_CONTACTNO," +
                    "PMS_EMERGENCY_CONTACTNO,PMSSTR_LOCAL_ADDRESS,PMSSTR_PERMANENT_ADDRESS,PMSSTR_QUALIFICATION," +
                    "PMSDT_ANNIVERSARY_DATE,PMSDT_JOINING_DATE,PMSNUM_RELIEVE_DATE,PMSSTR_IP_ADDRESS," +
                    "PMSSTR_SYSTEM_DETAIL,PMSNUM_IS_ACTIVE,PMSNUM_USER_TYPE,PMSSTR_PASSWORD) " 
                    + " VALUES("+id+",'"+user_name+"',to_date('"+user_dob+"','dd-mm-yyyy'),'"+user_gender+
                    "',"+user_designationCode+","+user_CdacId+","+user_deptId+",'"+user_CdacEmailId +
                    "','"+user_otheremailId+"',"+user_contactNo+","+user_emergencyNo+",'"+user_localAdd +
                    "','"+user_Permanentadd+"','"+user_Qualification+"',to_date('"+user_Anniversary+"','dd-mm-yyyy'),to_date('"+user_JoiningDate+
                    "','dd-mm-yyyy'),to_date('"+user_RelievingDate+"','dd-mm-yyyy'),'"+user_IpAdd+"','"+user_SystemDetail+
                    "',"+user_IsActive+","+user_UserType+",'"+user_password+"')";

        System.out.print(sql);

            st.execute(sql);
            out.println("'"+user_name+"'" + "Data Inserted Successfully");

              }



            rs.close();
            st.close();
            conn.close();
              }

            catch (Exception e) {
                e.printStackTrace();
                try {
                    conn.rollback();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }finally{
                try {
                    conn.close();
                } catch (SQLException e) {

                    e.printStackTrace();
                }
            }
            }
}

IS THIS CODE IS CORRECT FOR GENERATING NEW USER ID PLZ REPLY

View Answers

April 3, 2012 at 12:56 PM









Related Tutorials/Questions & Answers:
Servlet
Servlet  What is Servlet
Servlet
Servlet  how to navigate one servlet page to another servlet page
Advertisements
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  How many times the servlet is accessed
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  how to interact with a servlet from a swing program
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  i want to create a login page with servlet using database mysql? only in servlet not in jsp plzz help me out
Servlet
override Service method in the servlet when you extend GenericServlet to create servlet as it is mandatory to override it. But, when you extend HttpServlet to create a servlet then you can't override service method as there is a need to override
Servlet
Servlet  What must be implemented by all Servlets?    The Servlet Interface must be implemented by all servlets
servlet
servlet  how to create a login form using servlet using submit,edit delete button
servlet
servlet  dear sir servlet and html not run on eclips plz help me
servlet
servlet  i want a program for counting the no of times the servlet has been invoked
servlet
servlet  can i stoar record in variable which selected from table in servlet
servlet
of the Servlet API. It contains the classes necessary for a standard, protocol-independent servlet. Every servlet must implement the Servlet interface in one
Servlet
Servlet  I want to know the steps to write a simple servlet program... .   Hello Friend, Follow these steps: Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet. import java.io.*; import
Servlet
Servlet   Why is Servlet so popular?   Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web
servlet
servlet  i want to use servlet application on my web page then what should i do. I have already webspace.   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Servlet Tutorials Thanks
servlet
servlet  how to read a file from different folder using filereader in servlet   Hello Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/servlets/servlet-read-file.shtml Here you
Servlet
Servlet  Can a user defined function be included in a servlet? I need information regarding servlet syntax and not JSP.   Yes, you can create user defined function in Servlets. Have a look at the following link: http
servlet
servlet  I want the full coding for uploading a file in local drive D usin jsp,java class and servlet... help me thanks in advance....   ... and servlet please and thanks in advance
Servlet
Servlet  Hi, Can any one please expalin me below topics SERVLET ENGINE 2.WHY SUPER.INIT(); Thanks alot in advance!! Regards: Akash
servlet
servlet   Dear Deepak, is it compulsary to write the sevice() becoz i ve seen some example which does not ve sevice()..is it tue? plz replay me with thanks praveen
servlet
servlet  plz can anyone give me the link of javax library jar file. i badly need that. thanks in advance   Please visit the following link: Download Servlet API
servlet
servlet  I want a fully readymade project on online voting system with code in java servlet and database backend as msaccess.can u plz send me as soon as possible
Servlet
the same error <web-app> <servlet> <servlet-name>InsertServlet</servlet-name> <servlet-class>InsertServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>
servlet
servlet file which prints out the user's inputs. I need to use the post method to pass the data from html to the java servlet and also use both doGet and doPost methods in the servlet. I think, but unfortunately I have a terrible teacher
SERVLET
to the servlet and if the user id is correct then a new page will be displayed with his... pass to the servlet and all the fields brlongs to that id will be appear... will be done by using jsp and servlet... Plz help me,im really tensed...........  
servlet
servlet  hi sir,this is ashok.i installed tomcat 6.0 and jdk-150.i checked the server it's working but when execute servlet program for the .class file it shows the errors javax.servlet is not exist.what can i do,please tell me
servlet
to servlet. So, if anyone can help me so I can see how to connect the two I would
servlet
servlet  How do we define an application level scope for servlet?   Application scope uses a single namespace, which means all your pages should be careful not to duplicate the names of application scope objects
servlet
servlet  how to jsp integer are type cast int servlet page   Hi Friend, Try the following code:ADS_TO_REPLACE_1 1)form.jsp: <form method="post" action="../Data"> Enter Number:<input type="text" name="num
servlet
servlet   try { con=DaoPack.createConnection(); } catch(Exception e) { e.printStackTrace(); } if(request.getParameter("addproduct")!=null) { ProductBean bean=new ProductBean
servlet
servlet   try { con=DaoPack.createConnection(); } catch(Exception e) { e.printStackTrace(); } if(request.getParameter("addproduct")!=null) { ProductBean bean=new ProductBean
servlet
com.ilp.tsi.pm.services.StockService; /** * Servlet implementation class AddServlet1 */ //Servlet for Adding the stock public class AddStockServlet extends...; import com.ilp.tsi.utils.*; /** * Servlet implementation class Changepwd
servlet
); } } } this is the code for .java servlet am able to run
servlet
com.ilp.tsi.um.bean.BankBean; import com.ilp.tsi.um.service.BankService; /** * Servlet
on servlet - JSP-Servlet
on servlet deployment  What we'll get on servlet deployment
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
servlet - Servlet Interview Questions
Servlet Priority  How to set priority for servlet?  in web.xml file we can set priority of servlet. 1 2
servlet - Servlet Interview Questions
servlet  what is the full form of servlet
servlet - Servlet Interview Questions
servlet  what is the full form of servlet
servlet Service
servlet Service  Defined servlet Service
servlet initialization
servlet initialization  define servlet initialization
Servlet Context
Servlet Context  Defined Servlet Context
servlet container
servlet container  What is servlet container
Servlet chaining
Servlet chaining  What is Servlet chaining
servlet - JSP-Servlet
servlet navigation problem  Hi, i am facing problem in Servlet navigation

Ads