Guest User

Untitled

a guest
Feb 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. <form>
  2. <div id="eTable">
  3. <p:dataTable value="#{feeding.updateData()}" var="avv">
  4. <p:column headerText="No.">
  5. <h:outputText value="#{avv.ID}" />
  6. </p:column>
  7. <p:column headerText="Utterance">
  8. <h:outputText value="#{avv.editUtterance}" />
  9. </p:column>
  10. <p:column headerText="Device response">
  11. <h:outputText value="#{avv.editDeviceResponse}" />
  12. </p:column>
  13. <p:column headerText="Comments">
  14. <h:outputText value="#{avv.editComments}" />
  15. </p:column>
  16. <p:column>
  17. <center> <p:commandButton value="Delete" action="#{feeding.delete(avv.ID)}"/> </center>
  18. </p:column>
  19. </p:dataTable>
  20. </div>
  21.  
  22. List<feeding> editboard;
  23.  
  24. public List<feeding> getEditBoard() {
  25. return editboard;
  26. }
  27.  
  28. public List<feeding> updateData() {
  29. editboard = new ArrayList<feeding>();
  30. try {
  31.  
  32. Class.forName("com.mysql.jdbc.Driver");
  33. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/combi", "root", "#doubleinfinity7");
  34. ResultSet rs = null;
  35. conn.setAutoCommit(false);
  36. String str = "select * from device_assessment";
  37. PreparedStatement pst = conn.prepareStatement(str);
  38.  
  39. rs = pst.executeQuery(str);
  40. while (rs.next()) {
  41. feeding usrr = new feeding();
  42. usrr.setEditUtterance(rs.getString("utterance"));
  43. usrr.setEditDeviceResponse(rs.getString("response"));
  44. usrr.setEditComments(rs.getString("comments"));
  45. usrr.setID(rs.getLong("ID"));
  46.  
  47. editboard.add(usrr);
  48. Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
  49. List<feeding> checkedItems = new ArrayList<feeding>();
  50. for (feeding item : editboard) {
  51. if (checked.get(item.getID()) != null) {
  52. checkedItems.add(item);
  53.  
  54. usrr.delete(usrr.getID());
  55. }
  56. }
  57. }
  58.  
  59. } catch (ClassNotFoundException | SQLException e) {
  60. throw new FacesException(e);
  61. }
  62.  
  63. return editboard;
  64.  
  65. }
  66.  
  67. public void delete(long ID) {
  68. if (ID != 0) {
  69. System.out.println(" current ID : " + ID);
  70.  
  71. FacesContext context = FacesContext.getCurrentInstance();
  72. try {
  73.  
  74. Class.forName("com.mysql.jdbc.Driver");
  75. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/combi", "root", "#doubleinfinity7");
  76. conn.setAutoCommit(false);
  77. String sql = "delete from device_assessment where ID=" + ID;
  78. PreparedStatement pst = conn.prepareStatement(sql);
  79.  
  80. int i = pst.executeUpdate();
  81. if (i > 0) {
  82. System.out.println("Row deleted successfully");
  83. }
  84.  
  85. conn.commit();
  86.  
  87. context.addMessage(null, new FacesMessage("Successfully", "Deleted"));
  88.  
  89. } catch (ClassNotFoundException | SQLException e) {
  90. throw new FacesException(e);
  91. }
  92. }
  93.  
  94. }
Add Comment
Please, Sign In to add comment