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

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

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

Ads









Related Tutorials/Questions & Answers:
what is wrong with my JSP codes for updating a form?
What's wrong with my pagination code in JSP?
Advertisements
What is wrong with my servlet?
What is wrong with this line
what is wrong with this program
what is wrong in this program
what is wrong in this program......
Needed jsp codes
Not sure whats wrong with my code HELP PLEASE?!?!
ModuleNotFoundError: No module named 'forml'
ModuleNotFoundError: No module named 'formv'
ModuleNotFoundError: No module named 'formy'
JSP WITH MULTIPLE FORMS
what are the codes for uploading and downloading files in and from database?
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
What is JSP is in layman's terms?
Wrong parameter values while exporting data from jsp to excel
Multiple Forms in JSP
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
what is wrong in this program?I have netbeans 7.0 & jdk 7. please do corrections.
ModuleNotFoundError: No module named 'odoo10-addon-account-invoice-pro-forma-sequence'
ModuleNotFoundError: No module named 'odoo10-addon-account-invoice-pro-forma-sequence'
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
What is the difference between JSF, Servlet and JSP?
What is the best way to learn Java on my own?

Ads