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



Home Answers Viewqa JSP-Servlet How to edit values in textboxes from database using jsp

Have Programming Question? Ask it here!
 
 
 


lissy
How to edit values in textboxes from database using jsp
0 Answer(s)      3 years and 10 months ago
Posted in : JSP-Servlet


Hi RoseIndia,

I need help to solve my technical problem, i want to edit values in textboxes from database table using jsp, here is my code Please can anyone help me

editData.jsp

<%@ page language="java" import="java.util.*;"%> <%@ page language="java" import="java.sql.*"%>

<%! String IPAddress = ""; String SubnetMask = ""; String AggregatedSwitch = ""; String AllocatedHostname = ""; String VLANID = ""; String HeadendName = ""; String DateIssued = ""; String Remarks = "";

    %>

    <br><br><br>
    <table align="center" width="300px" style="background-color:#EDF6EA;border:1px solid #000000;">

        <tr><td colspan=2 style="font-weight:bold;" align="center">Edit User</td></tr>
        <tr><td colspan=2 align="center" height="10px"></td></tr>
        <tr>
            <td>IP Address</td>
            <td><input type="text" name="IPAddress" value="<%=IPAddress%>"></td>
        </tr>
        <tr>
            <td>Subnet Mask</td>
            <td><input type="text" name="SubnetMask" value="<%=SubnetMask%>"></td>
        </tr>
        <tr>
            <td>Aggregated Switch</td>
            <td><input type="text" name="AggregatedSwitch" value="<%=AggregatedSwitch%>"></td>
        </tr>
        <tr>
            <td>Allocated Hostname</td>
            <td><input type="text" name="AllocatedHostname" value="<%=AllocatedHostname%>"></td>
        </tr>

        <tr>
            <td>VLAN ID</td>
            <td><input type="text"  name="VLANID" value="<%=VLANID%>"></td>
        </tr>
        <tr>
            <td>Headend Name</td>
            <td><input type="text" name="HeadendName" value="<%=HeadendName%>"></td>
        </tr>
        <tr>
            <td>Date Issued</td>
            <td><input type="text" name="DateIssued" value="<%=DateIssued%>"></td>
        </tr>
        <tr>
            <td>Remarks</td>
            <td><input type="text" name="Remarks" value="<%=Remarks%>"></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
        </tr>
        <tr><td colspan=2 align="center" height="10px"></td></tr>
    </table>
    <%
                IPAddress = request.getParameter("IPAddress");
                SubnetMask = request.getParameter("SubnetMask");
                AggregatedSwitch = request.getParameter("AggregatedSwitch");
                AllocatedHostname = request.getParameter("AllocatedHostname");
                VLANID = request.getParameter("VLANID");
                HeadendName = request.getParameter("HeadendName");
                DateIssued = request.getParameter("DateIssued");
                Remarks = request.getParameter("Remarks");
                Statement stmt;
                Connection conn = null;
                String url = "jdbc:odbc:Driver={Microsoft Access Driver "
                        + "(*.mdb, *.accdb)};DBQ=C:\\Database\\Databaseip.accdb";
                String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
                out.println(request.getRequestURI());
                if (IPAddress != null && SubnetMask != null && AggregatedSwitch != null && AllocatedHostname != null && VLANID != null && HeadendName != null && DateIssued != null && Remarks != null) {
                    if (IPAddress != "" && SubnetMask != "" && AggregatedSwitch != "" && AllocatedHostname != "" && VLANID != "" && HeadendName != "" && DateIssued != "" && Remarks != "") {
                        try {
                            Class.forName(driver).newInstance();
                            conn = DriverManager.getConnection(url);
                            System.out.println("Connected to the database");

                            //ArrayList al = null;
                            // ArrayList userList = new ArrayList();
                            String query = "UPDATE ip_address SET IPAddress= "+IPAddress+",SubnetMask=" + SubnetMask + ",AggregatedSwitch=" + AggregatedSwitch + ",AllocatedHostname=" + AllocatedHostname + ",VLANID=" + VLANID + ",HeadendName=" + HeadendName + ",DateIssued=" + DateIssued + ",Remarks=" + Remarks + "";
                    stmt = conn.createStatement();

                    int i = stmt.executeUpdate(query);
                    System.out.println("query" + query);
                            if (i > 0) {
                                response.sendRedirect("adminHome.jsp");
                            }
                            conn.close();
                            System.out.println("Disconnected from database");
    %>
    <br>
    <TABLE style="background-color: #E3E4FA;"
           WIDTH="30%" border="1">
        <tr><th>Data Modified successfully
                in database.</th></tr>
    </TABLE>
    <%

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }

    %>
</form>

This code is not working its not displaying any values in the textboxes, it simply displays the textboxes empty, Please can anyone help me....

Thanks in advance


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com