Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void modifierElement(int id, String nom, int prix, int qnt) {
- try {
- String query = "UPDATE element SET element='" + nom
- + "', prix=" + prix
- + ", quantite=" + qnt
- + " WHERE id=" + id;
- cnx = connecterDB();
- st = cnx.createStatement();
- st.executeUpdate(query);
- System.out.println("Produit bien modifié");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
- public static Connection connecterDB() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- //System.out.println("Driver oki");
- String url = "jdbc:mysql://127.0.0.1:3306/taxiphone";
- String user = "root";
- String password = "";
- Connection cnx = DriverManager.getConnection(url, user, password);
- //System.out.println("Connexion bien établié");
- return cnx;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- TableElement.setEditable(true);
- clmID.setCellFactory(TextFieldTableCell.forTableColumn());
- clmELement.setCellFactory(TextFieldTableCell.forTableColumn());
- clmPrix.setCellFactory(TextFieldTableCell.forTableColumn());
- clmQuantite.setCellFactory(TextFieldTableCell.forTableColumn());
- actionCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Person,HBox>, ObservableValue<HBox>>() {
- @Override
- public ObservableValue<HBox> call(CellDataFeatures<Person, HBox> currentRow)
- {
- Button updateButton = new Button("update");
- Button deleteButton = new Button("delete");
- updateButton.setOnAction(e->{
- //Database operation to update record goes here
- });
- deleteButton.setOnAction(e->{
- //Database operation to deleted record goes here
- });
- ObservableValue<HBox> s = new SimpleObjectProperty<>(new HBox(updateButton,deleteButton));
- return s;
- }
- });
Add Comment
Please, Sign In to add comment