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.7K
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 325
1 DamithSL 300
2 Sergey Alexandrovich Kryukov 289
3 CPallini 235
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web04 | 2.8.141216.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