what is wrong with my JSP codes for updating a form?



Share on Google+Share on Google+

what is wrong with my JSP codes for updating a form?
0 Answer(s)      6 years and 5 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.


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 {
                conn = DriverManager.getConnection("jdbc:mysql://localhost/ADFJA) 
                stmt = conn.createStatement();
            } catch (Exception e) {
            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;

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

<%} 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.";
            <form action="Update.jsp" method ="post" name="update">
        <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">
                <tr><td>Tutor's ID</td>
                    <td><%= selectionId%></td>
                    <td>Full Name</td>
                    <td><input type="text" id="txtFullName" name="txtFullName" value="<%=strName%>"></td>
     <input type="submit" id="btnSubmit" name="Update Member" value="Update Member<%= request.getParameter("ID")%>">
    <a href ="logout.jsp">Log Out</a>

I hope to hear from you soon. Thanks.

View Answers

Related Tutorials/Questions & Answers:


Advertisement null