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 8522867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:14:55+00:00 2026-06-11T07:14:55+00:00

I have a database Table where I can edit a value. I want to

  • 0

I have a database Table where I can edit a value. I want to update the same, below is the code that I have tried.

The table code is as below

<table border="1px">
    <tr>
        <td><b>DBID</b></td>
        <td><b>Query Raised</b></td>
        <td><b>Time Raised</b></td>
        <td><b>Query Answered</b></td>
        <td><b>Time Answered</b></td>
    </tr>
<%
try {
    ps = con.prepareStatement("Select DBID, Query_Raised, TR, Query_Answered, TA from Scope1 where TR!='null'");

    rs = ps.executeQuery();

    while(rs.next()) {
%>
    <tr>
        <td><%=rs.getString("DBID")%></td>
        <td><input type="Text" value="<%=rs.getString("Query_Raised")%>" name="Updat"></td>
        <td><%=rs.getString("TR")%> </td>
        <td><%=rs.getString("Query_Answered")%></td>
        <td><%=rs.getString("TA")%></td>
        <td><input type="Submit" value="Update"></td>
    </tr>
<%
    } // while loop ends here

    rs.close();
    con.close();
} catch(Exception e) {
    out.println(e);
}
%>
</table>

and the update query that is used is:

String a = request.getParameter("Updat");

ps = con.prepareStatement("Update Scope1 Set Query_Raised = '" + a + "'");

int i = ps.executeUpdate();

if(i == 1) {
    out.print("Done");
} else{
    out.print("Erro");
}

I wanted to know the where condition that I should use to update the data in same page.

Thanks

  • 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-06-11T07:14:57+00:00Added an answer on June 11, 2026 at 7:14 am

    I understand the first code part in the question is a JSP say update.jsp and the second part it seems is your servlet, say UpdateServlet.

    So in your update.jsp on every row you have an <input type="text"> and submit button, but the <form> I think is only one which must be outside the <table>, so here goes my solution (choose any one):

    1. Use multiple <form> tags for each row, like

      <form action="whatever_action_you_have_which_calls_the_servlet"
            name="form<%=rs.getString("DBID")%>"
            id="formID<%=rs.getString("DBID")%>">
         // Including name and id so that the different forms remain unique
          <tr>
              <td><%=rs.getString("DBID")%></td>
              <td><input type="Text" value="<%=rs.getString("Query_Raised")%>" name="Updat"></td>
              <td><%=rs.getString("TR")%> </td>
              <td><%=rs.getString("Query_Answered")%></td>
              <td><%=rs.getString("TA")%></td>
              <td><input type="Submit" value="Update"></td>
          </tr>
      </form>
      

      So when you click on submit it would submit the <form> for which the submit button was clicked and would submit only the input which was edited and voila! your servlet code also works fine.

    2. You can have both the blocks of code in the same JSP, then use the <form> code snippet as described in point#1 and the second code snippet would be:

      String a = request.getParameter("Updat");
      
      if ( (a is not empty) or (a is not null)  ) {
          ps = con.prepareStatement("Update Scope1 Set Query_Raised = '" + a + "'");
      
          int i = ps.executeUpdate();
      
          if(i == 1) {
              out.print("Done");
          } else{
              out.print("Error");
          }
      }
      
      ...
      
      <form action="whatever_action_you_have_which_will_call_this_JSP" ...>
          <tr> ... your code as in point#1
          </tr>
      </form>
      
    3. Use ajax and other javascript DOM manipulative methods to accomplish this as said by Endy.
      For this you will need to have JSP (to display) & Servlet (to update the code).
      This might be a little more effort but you will learn Ajax and will be a little more close to real world.
      By far jQuery ajax is the simplest to use.

    Note:
    Just for the record, I know you might be practicing but if you are planning to use it in a real project then please read ahead.

    It is a bad-practice to use scriptlets in JSP (unless really required and that too if it is for view-level logic and not business or data-level logic) and even worse is to use JDBC code inside a JSP. So it would be really great if you could follow f_puras’s advice.

    If you are wondering why I should listen to your unsolicited advice then here is some food for thought:

    • How to avoid scriptlets in JSP
    • Scriptless JSPs
    • Why JSP = JDBC is bad

    Hope this helps.

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

Sidebar

Related Questions

Problem: I have a value in a database table. This value can either contain
I have a database table with some rows that I want to fetch using
I want to have a database table that keeps data with revision history (like
Some background: I have an database that I want to use linq-to-sql to update
I have a database table which link locations together; a location can be in
I have a table of pages in my database, each page can have a
Anyone have a PL-SQL statement that i can use to generate database & tables
that my problem: I have database table like that: id (AI) market_id 1 6
EDIT: Changed as I have a different issue with the same code 2nd Edit:
Edit: I've updated the code below so that it now works, thanks to Rob's

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.