Guest User

Untitled

a guest
Apr 10th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. else if (Item == 1)
  2. { /* Computer List) */
  3. comboBoxOrderBy.setModel(new DefaultComboBoxModel(new String[] { "computer_id", "cpu_model",
  4. "cpu_clock", "ram", "hdd", "os", "archit", "computer_name", "computer_type",
  5. "computer_brand", "computer_model", "serial_number", "status" }));
  6. comboBoxOrderBy.addActionListener(
  7. new ActionListener()
  8. { /*
  9. * ACÇAO DA CAIXA
  10. * ORDER BY
  11. */
  12. public void actionPerformed(ActionEvent arg0)
  13. {
  14. String teste = (String)comboBoxOrderBy.getSelectedItem();
  15. JOptionPane.showMessageDialog(frmInventoryDatabaseManager, teste);
  16. try
  17. {
  18. /*
  19. * BEGINING OF DATABASE REQUEST
  20. */
  21. Connection lig = DriverManager.getConnection(
  22. "jdbc:mysql://localhost/inventorydb", "root", "");
  23. PreparedStatement inst = lig.prepareStatement(
  24. "SELECT computer_id, cpu_model, cpu_clock, ram, hdd, "
  25. + "os, archit, computer_name, computer_type, computer_brand, "
  26. + "computer_model, serial_number, status FROM computerlist ORDER BY ? ASC");
  27. inst.setString(1, teste);
  28. ResultSet rs = inst.executeQuery();
  29. table1.setModel(DbUtils.resultSetToTableModel(rs));
  30. lig.close();
  31. /*
  32. * END OF DATABASE REQUEST
  33. * SERVICES
  34. */
  35. }
  36. catch (SQLException e1)
  37. {
  38. JOptionPane.showMessageDialog(frmInventoryDatabaseManager,
  39. "Impossivel ligar á base de dados: "
  40. + e1.getLocalizedMessage());
  41. }
  42. }
  43. });
  44. }
  45.  
  46. suaTable.setAutoCreateRowSorter(true);
Add Comment
Please, Sign In to add comment