Home Answers Viewqa JSP-Servlet what is wrong with my JSP codes for updating a form?

 
 


Karen
what is wrong with my JSP codes for updating a form?
0 Answer(s)      a year and 11 months ago
Posted in : JSP-Servlet

Hi experts,

I have tried to emulate a code from a textbook but it doesn't work in my program. Hope someone can advise me where I had gone wrong.

Tks.

I've set up my database as follows:-

ID - autoincrement and it's INT. NRIC No - String. Name - String.

Here's snippet of my codes:-

<%    Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            Statement stmt = null;

            try {
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection("jdbc:mysql://localhost/ADFJA) 
                stmt = conn.createStatement();
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
            if (request.getParameter("action") != null) {
                int selectionId = Integer.parseInt(request.getParameter("ID"));
                String NRIC = request.getParameter("txtNRIC");
                String Name = request.getParameter("txtFullName");
String sql = "UPDATE tutors SET strNRICNO='" + NRIC
                        + " ', strTutorName=' " + Name + "'where ID= " + selectionId;
                //out.println(sql);
                stmt.executeUpdate(sql);

%>
<html>
    Member Id = <%= request.getParameter("ID")%> Successfully Updated ! <br><br>

</html>
<%} else {%>
<%
                int selectionId = Integer.parseInt(request.getParameter("ID"));
                String MemberNo = null;

String strNRIC = null;
                String strName = null;
rs = stmt.executeQuery("select * from Members where ID = "   + selectionId + "");
                if (rs.next()) {
                    strNRIC = rs.getString("strNRICNO");
                    strTutorName = rs.getString("strTutorName");
  } else {
                    strNRIC = "Unkown.";
                    strTutorName = "Unkown.";
  </head>
    <body><center>
            <form action="Update.jsp" method ="post" name="update">
        </center>
        <input type="hidden" value="list" name="action">
        <input type="hidden" value=<%= request.getParameter("ID")%> name="ID"">
        <div id="header">Welcome to Admin</div>
                    <h5>Member Update Form </h5>
            <input type = "hidden" value="list" name="action">
            <table>
                <tr><td>Tutor's ID</td>
                    <td><%= selectionId%></td>
                <tr>
                    <td>Full Name</td>
                    <td><input type="text" id="txtFullName" name="txtFullName" value="<%=strName%>"></td>
                </tr>
                <tr>
     <input type="submit" id="btnSubmit" name="Update Member" value="Update Member<%= request.getParameter("ID")%>">
            </td></tr>
    </table>
    <a href ="logout.jsp">Log Out</a>
</div>
</form>
</body>
</html>
<%}%

I hope to hear from you soon. Thanks.

View Answers









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.