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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:02:41+00:00 2026-05-31T06:02:41+00:00

I have the following code to update a record. The code compiles however it

  • 0

I have the following code to update a record. The code compiles however it skips everything in the try statement and displays the error message in the catch statement. I am not sure what it is that I am missing as it doesn’t display any sort of syntax error.

try {           
    PreparedStatement st = db.con.prepareStatement("UPDATE item SET Name = ?, Size = ?, Price = ?, WHERE ItemCode = ?");
    st.setString(1, textArea_Code.getText());
    st.setString(2, textArea_name.getText());
    st.setString(3, textArea_size.getText());
    st.setString(4, textArea_price.getText());
    st.executeUpdate();

    JOptionPane.showMessageDialog(frame, "Updated");    

} catch (SQLException e ) {
    JOptionPane.showMessageDialog(frame, "update not successful");      
}
  • 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-31T06:02:42+00:00Added an answer on May 31, 2026 at 6:02 am

    You’re swallowing the exception, which is generally a bad idea. At the very least call e.printStackTrace() so that you have an output of the exception.

    As it happens, you have a syntax error in your SQL statement: UPDATE item SET Name = ?, Size = ?, Price = ?, WHERE ItemCode = ? – remove the comma from after Price = ?.


    To address the confusion about why the UPDATE statement still doesn’t work, despite fixing the syntax error, allow me to explain in more detail (far easier to do this in the answer, rather than in comments).

    The ? character in your SQL String is a placeholder for a value that you’ll set with one of the various set_() methods (in your case, only ever setString(). Each placeholder is numbered with an index starting from 1 – the first ? that appears in your string represents index 1, the second represents index 2, etc.

    Your SQL string looks like this:

    UPDATE item SET Name = ?, // 1
    Size = ?, // 2
    Price = ? // 3
    WHERE ItemCode = ? // 4
    

    You’re setting values for your placeholders like this:

    st.setString(1, textArea_Code.getText()); // ItemCode is fourth in the SQL, should be 4
    st.setString(2, textArea_name.getText()); // Name is first in the SQL, should be 1
    st.setString(3, textArea_size.getText()); // Size is second in the SQL, should be 2
    st.setString(4, textArea_price.getText()); // Price is third in the SQL, should be 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following javascript code, which loads without error, however the update function
I have the following code: UPDATE myTable SET Col1 = @Value However, I have
We have following code: try { // some code throwing MyException } catch (MyException
I have the following code in a Spring JdbcTemplate based dao - getJdbcTemplate().update(Record Insert
I have a gridview in an update panel with the following code to select
Using the following code I have been able to display a text message when
I'm getting caught up on PHP again, and have the following update code. This
I have the following code that I use in a Query to update a
I have following code to add or update the Entity object. finding the object
I have the following code - truck_mng is a record that as the data

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.