Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. @Override
  2. public void updateTask(Task task) {
  3.  
  4.  
  5. Connection con = null;
  6. PreparedStatement pstmt = null;
  7. try{
  8. DataSource ds = new DataSource();
  9. con = ds.createConnection();
  10. pstmt = con.prepareStatement(
  11. "UPDATE Tasks SET Title = ?, Priority = ?, IsComplete = ?, DateCompleted = ?, Note = ? WHERE TaskID = ?");
  12. pstmt.setString(1, task.getTitle());
  13. pstmt.setString(2, task.getPriority());
  14. pstmt.setInt(3, (task.getIsComplete()? 1:0));
  15. pstmt.setDate(4, task.getDateCompleted());
  16. pstmt.setString(5, task.getNote());
  17. pstmt.setInt(6, task.getTaskID().intValue());
  18. pstmt.executeUpdate();
  19. }
  20. catch(SQLException e){
  21. e.printStackTrace();
  22. }
  23. finally{
  24. try{ if(pstmt != null){ pstmt.close(); }}
  25. catch(SQLException ex){System.out.println(ex.getMessage());}
  26. try{ if(con != null){ con.close(); }}
  27. catch(SQLException ex){System.out.println(ex.getMessage());}
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement