Advertisement
Guest User

Untitled

a guest
Feb 7th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public static int update(User user) {
  2. ConnectionPool pool = ConnectionPool.getInstance();
  3. Connection connection = pool.getConnection();
  4. PreparedStatement ps = null;
  5.  
  6. String query = "UPDATE user SET username = ?, password = ?, email = ?, firstName = ?, lastName = ?"
  7. + "WHERE userID = ?";
  8.  
  9. try {
  10. ps = connection.prepareStatement(query);
  11. ps.setString(1, user.getUsername());
  12. ps.setString(2, user.getPassword());
  13. ps.setString(3, user.getEmail());
  14. ps.setString(4, user.getFirstName());
  15. ps.setString(5, user.getLastName());
  16. ps.setInt(6, user.getUserID());
  17. return ps.executeUpdate();
  18. } catch (SQLException e) {
  19. System.out.println(e);
  20. } finally {
  21. DBUtil.closePreparedStatement(ps);
  22. pool.freeConnection(connection);
  23. }
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement