Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:59:58+00:00 2026-05-28T02:59:58+00:00

I have a question on how to update a particular record in a database

  • 0

I have a question on how to update a particular record in a database using JSTL and java servlets.

Ok to call one record, I use a servlet to run a query to populate a jsp page using this type of format.

        ResultSet results = getRecords.executeQuery();  //run database query
        Result result = ResultSupport.toResult(results);  
        request.setAttribute("result", result);
        RequestDispatcher rd = request.getRequestDispatcher("/showReport.jsp");  //redirect to this page with query info
        rd.forward(request, response);

In the jsp page, I use this format to populate the page.
the row number is the corresponding to the index of the value on how the query is run.

    <c:forEach var="row" items="${result.rowsByIndex}"> 
<form action = "/runthis/servlet?id=${row[0]}" method = "get" >
    Employee Name<input type="text"  value="<c:out value="${row[2]}"/>" />
    Department<select>
    <option value="<c:out value="${row[4]}"/>"><c:out value="${row[4]}"/></option></select>
<input type="submit" value="Save">
</form>
    </c:forEach>

So for instance, if someone changes the Employee Name, but leaves the Department field alone, or vice versa, how would I go about this?

I think I should be able to kick this form action to a “update servlet”, but I would rather not “update” every element in the record if I do not need to.

Also I’m still learning web dev, so if you can think of a better way to prepopulate stuff, via javascript or whatever, I’m willing to try that as well, if it’s a possible solution.

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:59:58+00:00Added an answer on May 28, 2026 at 2:59 am

    i think you need to do something like this:

    <c:forEach var="row" items="${result.rowsByIndex}"> 
        <form action="/runthis/servlet" method="post">
            <input type="hidden" name="id" value="<c:out value="${row[1]}"/>" />
            <input type="hidden" name="EmployeeName_orig" value="<c:out value="${row[2]}"/>" />
            Employee Name<input type="text" name="EmployeeName" value="<c:out value="${row[2]}"/>" />
            <input type="hidden" name="Department_orig" value="<c:out value="${row[4]}"/>" />
            Department
            <select id="Department" name="Department">
                <option value="<c:out value="${row[4]}"/>"><c:out value="${row[4]}"/></option>
            </select>
            <input type="submit" value="Save" />
        </form>
    </c:forEach>
    

    and then, in your update servlet (here called /runthis/servlet) you do some form of update employee and set the name and department where the row is id. note that i send the id in a hidden field, but it could just as well be sent in the url as you mentioned in our discussion above!

    about your remark on updating every element in a record:

    this can be done in different ways. one way is to load the record from database first, and compare the fields to know what fields to update. but that would require an extra read from the database before the update.

    another way (the one i have prepared for in my proposed solution) is to have hidden fields, one for each input in your form. this hidden field holds the original value for its input counterpart. this way you can compare the original value with the new value without having to do a read from the database. on the other hand, you’re now transferring the double amount of data over the line for each post request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about using subqueries in an Update statement. My example: UPDATE
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have question regarding the use of function parameters. In the past I have
I have a newbie question in JSF, and particular in Richfaces. I need my
I have a question about a particular query I'd like to execute against a
I have a List<HashMap<String,Object>> which represents a database where each list record is a
I have written a task that will run periodically to recalculate and update the
Update : I have changed this question to be about the specific problem I
I have been using Dreamweaver to build several sites. In particular, I utilize its
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.