title: How can I properly write a SQL query to update record data in a JTable?
body: <p>To better imagine the situation, I have a <code>Jtable</code> - which saves some records. When I want to edit a record - I have a button for this - I click on it, edit the cell. but the data is not saved, after refreshing the program, do not see the edited record, only the previous record.</p>
  <p><strong>query</strong>: <code>update employe set name = ?,salary = ?,number = ? where id = ?</code></p>
  <p>I suppose there is something wrong with the query ( not too specific?).
  The previous version of the program did not allow to point to a given record with the mouse, but I entered a given record for editing in the text field and the query worked - there I pointed to a specific id for editing, now it points only to a given cell.
  And I am wondering what is the problem, after all, the cell is edited but not saved?</p>
  <pre><code>updateButton.addActionListener(e -&gt; {
              String id, name, salary, mobile;
              name = txtName.getText();
              salary = txtSalary.getText();
              mobile = txtNumber.getText();
              id = txtID.getText();
  
              try {
                  updateSelectedRows(table);// allows to edit cells with the mouse
  
                  pst = con.prepareStatement(&quot;update employe set name = ?,salary = ?,number = ? where id = ?&quot;);
                  pst.setString(1, name);
                  pst.setString(2, salary);
                  pst.setString(3, mobile);
                  pst.setString(4, id);
  
                  pst.executeUpdate();
                  tab_show();//refresh table, SELECT database query
                  txtName.setText(&quot;&quot;);
                  txtSalary.setText(&quot;&quot;);
                  txtNumber.setText(&quot;&quot;);
                  txtName.requestFocus();
              } catch (SQLException e1) {
                  e1.printStackTrace();
              }
  </code></pre>
  <p>function <code>updateSelectedRows</code>:</p>
  <pre><code>public void updateSelectedRows(JTable table) {
  
          DefaultTableModel model = (DefaultTableModel) table1.getModel();
          int i = table.getSelectedRow();
          model.setValueAt(txtName.getText(), i, 1);
          model.setValueAt(txtSalary.getText(), i, 2);
          model.setValueAt(txtNumber.getSelectedItem(), i, 3);
  
      }
  </code></pre>