I am doing a project where i need to edit values in textboxes from database using jsp, here is my code, Please can anyone help me to solve this:


<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");%>
        <TITLE>Fetching Data From a Database</TITLE>
        <H1>Fetching Data From a Database</H1>
                    Connection connection = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver "
                            + "(*.mdb, *.accdb)};DBQ=C:\\Database\\Databaseip.accdb");
                    ResultSet resultset;
                    Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                    String AggregatedSwitch = request.getParameter("AggregatedSwitch");
                    resultset =
                            statement.executeQuery("SELECT * FROM ip_address WHERE AggregatedSwitch = '" + AggregatedSwitch + "'");
                    if (!resultset.next()) {
                        out.println("Sorry, could not find the data. ");
                    } else {
        <TABLE cellpadding="15" border="1" style="background-color: #ffffcc" align="center">
                <TH>IP Address</TH>
                <TH>Subnet Mask</TH>
                <TH>Aggregated Switch</TH>
                <TH>Allocated Hostname</TH>
                <TH>VLAN ID</TH>
                <TH>Headend Network</TH>
                <TH>Date Issued</TH>


                                        do {

                <TD> <%=  resultset.getString(1)%> </TD>
                <TD> <%= resultset.getString(2)%> </TD>
                <TD> <%= resultset.getString(3)%> </TD>
                <TD> <%= resultset.getString(4)%> </TD>
                <TD> <%= resultset.getString(5)%> </TD>
                <TD> <%= resultset.getString(6)%> </TD>
                <TD> <%= resultset.getString(7)%> </TD>
                <TD> <%= resultset.getString(8)%> </TD>

                <TD><input type="button" name="edit" value="Edit" onClick="javascript:window.location='editData.jsp';" style="background-color:#49743D;font-weight:bold;color:#ffffff;">

                <TD><input type="button" name="delete" value="Delete" onClick="javascript:window.location='deleteData.jsp';"style="background-color:#ff0000;font-weight:bold;color:#ffffff;"></TD>
                                        } while (resultset.isAfterLast() != true);




<%@ page language="java" import="java.util.*;"%>
<%@ page language="java" import="java.sql.*"%>
    <form name="editform" method="post" action="editData.jsp">
        <%!            String IPAddress = "";
            String SubnetMask = "";
            String AggregatedSwitch = "";
            String AllocatedHostname = "";
            String VLANID = "";
            String HeadendName = "";
            String DateIssued = "";
            String Remarks = "";


        <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>
                <td>IP Address</td>
                <td><input type="text" name="IPAddress" value="<%=IPAddress%>"></td>
                <td>Subnet Mask</td>
                <td><input type="text" name="SubnetMask" value="<%=SubnetMask%>"></td>
                <td>Aggregated Switch</td>
                <td><input type="text" name="AggregatedSwitch" value="<%=AggregatedSwitch%>"></td>
                <td>Allocated Hostname</td>
                <td><input type="text" name="AllocatedHostname" value="<%=AllocatedHostname%>"></td>

                <td>VLAN ID</td>
                <td><input type="text"  name="VLANID" value="<%=VLANID%>"></td>
                <td>Headend Name</td>
                <td><input type="text" name="HeadendName" value="<%=HeadendName%>"></td>
                <td>Date Issued</td>
                <td><input type="text" name="DateIssued" value="<%=DateIssued%>"></td>
                <td><input type="text" name="Remarks" value="<%=Remarks%>"></td>
                <td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
            <tr><td colspan=2 align="center" height="10px"></td></tr>
                    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";
                    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 {
                                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) {
                                System.out.println("Disconnected from database");
        <TABLE style="background-color: #E3E4FA;"
               WIDTH="30%" border="1">
            <tr><th>Data Modified successfully
                    in database.</th></tr>

                            } catch (Exception e) {


with this code my ouput is it displays all the table values in a table fashion as per the form based input, at the end of each row it has edit and delete buttons, when i click edit button it shd edit all the values in that particular row in next jsp page, but am getting simply empty textboxes not the values, Please correct my code and solve this issue.. This is very urgent for me....

Thanks in advance

Recommended Answers

In editData.jsp the textboxes appears before calling request.getParameter() for each variable. For that reason every textbox is empty. Try to move the block of get parameters above, next to variable declarations.

Jump to Post

All 4 Replies

In editData.jsp the textboxes appears before calling request.getParameter() for each variable. For that reason every textbox is empty. Try to move the block of get parameters above, next to variable declarations.

Thanks for the reply, will try this.

thank you for your helping.. by selvamptl

selvampti .. is there any particular reason you chose to revive this thread?
no new answer, no new question ....
I'm puzzled as to your thoughts here ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.