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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:58:06+00:00 2026-06-10T05:58:06+00:00

when I select a row and press the remove button: In the swing interface

  • 0

when I select a row and press the “remove” button:

In the swing interface the selected row is removed (as expected). But

In the actual database the last row is deleted whatever the selected row was (not expected).
The deleted row is always the last row in the database, whatever the actual selected row was. There are no errors and no exceptions thrown in my code. it works without any interruptions.

I actually added the necessary things to my code:

  Statement sqlStatement = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

and Add a “remove” button to delete a selected row:

JButton removeEmployee = new JButton("Remove Selected");
removeEmployee.addActionListener(new ActionListener()
{
  public void actionPerformed(ActionEvent e)
  {
    dTableModel.removeRow(table.getSelectedRow());
    try
    {
      resultSet.absolute(table.getSelectedRow());
      resultSet.deleteRow();

    } catch (SQLException e1)
    {
      e1.printStackTrace();
    }
  }
});
  • 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-10T05:58:08+00:00Added an answer on June 10, 2026 at 5:58 am

    Thank you @Germann …

    I solved it, and I will provide the solution so that others can get help from it.

    You are right that resultSet.absolute(...); returns boolean value, but it also moves the cursor to the specified row in its argument resultSet.absolute(table.getSelectedRow());. So what was the problem.

    The problem is:
    The line dTableModel.removeRow(table.getSelectedRow()); mustn’t be called before resultSet.absolute(table.getSelectedRow()); because (the first) it removes the selected row, and because it is removed, the second method gets nothing selected, so table.getSelectedRow() returns -1. and as specified in the documentation, absolute(-1) moves the cursor to the last line, and that deletes the last row in the underlying database.

    So the solution is to reverse the order of those lines, and I prefer to make it after resultSet.deleteRow();

        JButton removeEmployee = new JButton("Remove Selected");
        removeEmployee.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            try
            {/* here I added +1 because it moves the row to the selected row -1 
                I don't know why. But it now works well */
              resultSet.absolute(table.getSelectedRow()+1);
              resultSet.deleteRow();
              dTableModel.removeRow(table.getSelectedRow());
            } catch (SQLException e1)
            {
              e1.printStackTrace();
            }
          }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a JQGrid grid, when you select a row and press the edit button,
I would like to select a row from the database based on two input
There are two scenarios: You select a row and press delete key to delete
How can I select a row from mysql query and save it to variable
If I were to select a row from a table I basically have two
I would like to select a row from 2 different tables that are relational.
Can someone tell me how can I select the Row under the one on
I have a dojox.grid.DataGrid where I want to select a row programmatically. I'm using
I have a UITableView , which when I select a row, I want to
My partialView is Opened in the modal dialog form, User select special row, I

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.