Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. TableColumn<datadetail, String> id =
  2. new TableColumn<datadetail, String>("Id");
  3. TableColumn<datadetail, String> email =
  4. new TableColumn<datadetail, String>("Email");
  5. TableColumn<datadetail, Date> datum =
  6. new TableColumn<datadetail, Date>("Datum");
  7.  
  8.  
  9. email.setCellValueFactory(new PropertyValueFactory<>("email"));
  10. email.setCellFactory(TextFieldTableCell.<datadetail> forTableColumn());
  11. email.setOnEditCommit((CellEditEvent<datadetail, String> event) -> {
  12. TablePosition<datadetail, String> pos = event.getTablePosition();
  13. String newEmail = event.getNewValue();
  14. int row = pos.getRow();
  15. datadetail datadetail = event.getTableView().getItems().get(row);
  16. datadetail.setEmail(newEmail);
  17. });
  18.  
  19. public void setEmail(String email) {
  20. this.id = id;
  21. this.email = email;
  22.  
  23. try {
  24. Class.forName("com.mysql.cj.jdbc.Driver");
  25. Connection con = DriverManager.getConnection(
  26. "jdbc:mysql://localhost/java","root","123456");
  27. // System.out.println("Connect success!");
  28.  
  29. PreparedStatement pstm = con.prepareStatement("update test set email = ? where id = ?");
  30. pstm.setString(1, email);
  31. pstm.setInt(2, id);
  32. int editemail = pstm.executeUpdate();
  33. pstm.executeUpdate();
  34. System.out.println("Updated " + editemail + " records");
  35. } catch (ClassNotFoundException ex) {
  36. System.out.println("ClassNotFoundException");
  37. System.out.println("Error message: " + ex);
  38. } catch (SQLException ex) {
  39. System.out.println("SQLException");
  40. System.out.println("Error message: " + ex);
  41. }
  42. }
  43.  
  44. public void setDatum(Date datum) {
  45. this.id = id;
  46. this.datum = datum;
  47.  
  48. try {
  49. Class.forName("com.mysql.cj.jdbc.Driver");
  50. Connection con = DriverManager.getConnection(
  51. "jdbc:mysql://localhost/java","root","123456");
  52. // System.out.println("Connect success!");
  53.  
  54. PreparedStatement pstm = con.prepareStatement("update test set datum = ? where id = ?");
  55. pstm.setString(1, datum);
  56. pstm.setInt(2, id);
  57. int editdatum = pstm.executeUpdate();
  58. pstm.executeUpdate();
  59. System.out.println("Updated " + editdatum + " records");
  60. } catch (ClassNotFoundException ex) {
  61. System.out.println("ClassNotFoundException");
  62. System.out.println("Error message: " + ex);
  63. } catch (SQLException ex) {
  64. System.out.println("SQLException");
  65. System.out.println("Error message: " + ex);
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement