Advertisement
Guest User

Untitled

a guest
Apr 19th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. package be.pxl.ticket.dao;
  2. import be.pxl.ticket.bean.TicketBean;
  3. import java.sql.Connection;
  4. import java.sql.Date;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9.  
  10.  
  11.  
  12. public class TicketDao {
  13.  
  14. private String url;
  15. private String user;
  16. private String password;
  17.  
  18. public TicketDao()
  19. {
  20.  
  21. }
  22.  
  23. public TicketDao(String url, String user, String password) {
  24. super();
  25. this.url = url;
  26. this.user = user;
  27. this.password = password;
  28. }
  29.  
  30. public String getUrl() {
  31. return url;
  32. }
  33.  
  34. public void setUrl(String url) {
  35. this.url = url;
  36. }
  37.  
  38. public String getUser() {
  39. return user;
  40. }
  41.  
  42. public void setUser(String user) {
  43. this.user = user;
  44. }
  45.  
  46. public String getPassword() {
  47. return password;
  48. }
  49.  
  50. public void setPassword(String password) {
  51. this.password = password;
  52. }
  53.  
  54. public TicketBean getTicketById(int id) throws SQLException
  55. {
  56. try(Connection con = getConnection();
  57. PreparedStatement stmt = con.prepareStatement("SELECT * FROM tickettable WHERE id=?"))
  58. {
  59. stmt.setInt(1, id);
  60. try(ResultSet rs = stmt.executeQuery())
  61. {
  62. if (rs.next())
  63. {
  64. TicketBean ticketBean = new TicketBean();
  65. ticketBean.setId(id);
  66. ticketBean.setTitle(rs.getString("title"));
  67. ticketBean.setDescription(rs.getString("description"));
  68. ticketBean.setCategory(rs.getString("catagorie"));
  69. ticketBean.setCreationDate(rs.getDate("creationDate"));
  70. ticketBean.setStatus(rs.getString("status"));
  71. ticketBean.setSubmittedBy(rs.getString("submittedBy"));
  72. ticketBean.setAssignedTo(rs.getString("assignedTo"));
  73. ticketBean.setLocation(rs.getString("location"));
  74.  
  75. return ticketBean;
  76.  
  77. }else
  78. {
  79. return null;
  80. }
  81. }
  82. }catch(SQLException e)
  83. {
  84. throw new SQLException(e);
  85. }
  86.  
  87. }
  88.  
  89. public void updateTicket(TicketBean ticketBean) throws SQLException
  90. {
  91. try(Connection con = getConnection();
  92. PreparedStatement stmt = con.prepareStatement("UPDATE tickettable SET title=?, description=?, "
  93. + "catagorie=?, creationDate=?, status=?, submittedBy=?, assignedTo=?, location=? WHERE id=?"))
  94. {
  95. stmt.setString(1, ticketBean.getTitle());
  96. stmt.setString(1, ticketBean.getDescription());
  97. stmt.setString(1, ticketBean.getCategory());
  98. stmt.setDate(1, (Date) ticketBean.getCreationDate());
  99. stmt.setString(1, ticketBean.getStatus());
  100. stmt.setString(1, ticketBean.getSubmittedBy());
  101. stmt.setString(1, ticketBean.getAssignedTo());
  102. stmt.setString(1, ticketBean.getLocation());
  103. stmt.executeUpdate();
  104. }
  105. catch (SQLException e) {
  106. throw new SQLException(e);
  107. }
  108. }
  109. //html helper methode
  110.  
  111. private Connection getConnection() throws SQLException {
  112. return DriverManager.getConnection(url,user,password);
  113.  
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement