Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com