Hello. Test program "Time of arrival-care staff." There is JComboBox which is filled from a DB (myaql). When you click on the "Arrived" button by an employee, the time for pressing this button is added to the database and displayed in the JTable. The problem is that each new employee should be displayed in a new line, and now he is simply replaced by a subsequent query.

comeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String user = (String) comboBox.getSelectedItem(); try { ResultSet rs = preparedStatement(String.format(query,user)).executeQuery(); table.setModel(resultSetToTableModel(rs)); } catch (SQLException e1) { e1.printStackTrace(); } pack(); } }); 

The resultSetToTableModel () method is a library method rs2xml.jar

  • Got it. Why do you have a user in your request? You have time for 1 user - everything is ok. So rewrite your request. - smackmychi
  • If you want the following functionality - only the user that is selected in the drop-down list is added to the table - you should create an add method, since resultSetToTableModel creates a model. Fills and returns the link. You also need: 1) Get the table model (getModel) 2) Bring it to the DefaultTableModel type 3) Call the addRow () method - add a new row In principle, knowing how the resultSetToTableModel method is implemented, you can likewise rivet the method that adds a string to the existing model from the dataset. - smackmychi
  • To get started, refer to the documentation [How To Use Tables] [1]. And it is worth examining the implementation of the resultSetToTableModel method — it can clarify a lot for you [Technojeeves: ResultSet To TableModel] [2] [1]: docs.oracle.com/javase/tutorial/uiswing/components/table.html [2]: technojeeves. com / index.php / 9-freebies / ... - smackmychi

0