Guest User

Untitled

a guest
May 11th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. public static void modifierElement(int id, String nom, int prix, int qnt) {
  2. try {
  3. String query = "UPDATE element SET element='" + nom
  4. + "', prix=" + prix
  5. + ", quantite=" + qnt
  6. + " WHERE id=" + id;
  7. cnx = connecterDB();
  8. st = cnx.createStatement();
  9. st.executeUpdate(query);
  10. System.out.println("Produit bien modifié");
  11.  
  12. } catch (SQLException e) {
  13. System.out.println(e.getMessage());
  14. }
  15.  
  16. }
  17.  
  18. public static Connection connecterDB() {
  19. try {
  20. Class.forName("com.mysql.jdbc.Driver");
  21. //System.out.println("Driver oki");
  22. String url = "jdbc:mysql://127.0.0.1:3306/taxiphone";
  23. String user = "root";
  24. String password = "";
  25. Connection cnx = DriverManager.getConnection(url, user, password);
  26. //System.out.println("Connexion bien établié");
  27. return cnx;
  28. } catch (Exception e) {
  29. e.printStackTrace();
  30. return null;
  31. }
  32. }
  33.  
  34. TableElement.setEditable(true);
  35. clmID.setCellFactory(TextFieldTableCell.forTableColumn());
  36. clmELement.setCellFactory(TextFieldTableCell.forTableColumn());
  37. clmPrix.setCellFactory(TextFieldTableCell.forTableColumn());
  38. clmQuantite.setCellFactory(TextFieldTableCell.forTableColumn());
  39.  
  40. actionCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Person,HBox>, ObservableValue<HBox>>() {
  41.  
  42. @Override
  43. public ObservableValue<HBox> call(CellDataFeatures<Person, HBox> currentRow)
  44. {
  45. Button updateButton = new Button("update");
  46. Button deleteButton = new Button("delete");
  47.  
  48. updateButton.setOnAction(e->{
  49. //Database operation to update record goes here
  50. });
  51.  
  52. deleteButton.setOnAction(e->{
  53. //Database operation to deleted record goes here
  54. });
  55.  
  56.  
  57.  
  58. ObservableValue<HBox> s = new SimpleObjectProperty<>(new HBox(updateButton,deleteButton));
  59.  
  60.  
  61. return s;
  62. }
  63. });
Add Comment
Please, Sign In to add comment