Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: database Servlet
Sir,below program is to connect servelt to DB createaccount. not getting what is the mistake in it.database is not updated. can you please tell me the solution?
 

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
 
        String fname=request.getParameter("fname");
        String lname=request.getParameter("lname");
        String gender=request.getParameter("gender");
        String dob=request.getParameter("dob");
        String addr=request.getParameter("addr");
        String email=request.getParameter("email");
        String phone=request.getParameter("phone");
        String duname=request.getParameter("duname");
        String dupwd=request.getParameter("dupwd");
 
        try{
 

        Class.forName("org.apache.derby.jdbc.ClientDriver");
        Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/ers","root","root");
        Statement stmt = conn.createStatement();
        String sql = "insert into app.createaccount values('"+fname+"','"+lname+"','"+gender+"','"+dob+"','"+addr+"','"+email+"','"+phone+"','"+duname+"','"+dupwd+"')";
 
        System.out.println(sql);
        int s=stmt.executeUpdate(sql);
        if(s==0)
        {
           request.getRequestDispatcher("CreateAccSuccess.jsp").forward(request,response);
        }
 else
        {
            request.getRequestDispatcher("CreateAccFailure.jsp").forward(request,response);
 }
 
    }catch(Exception e )
    {
        e.printStackTrace();
    }
    }
Posted 6-Jul-13 7:45am
vidyars260
Edited 9-Jul-13 4:08am
(no name)10.6K
v3
Comments
Nirav Prabtani at 9-Jul-13 9:33am
   
did you mean data is not inserted????
vidyars at 10-Jul-13 7:02am
   
yes. Data is not inserted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 9 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100