Advertisement
Guest User

Untitled

a guest
May 16th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. private void updateHitCounter() {
  2. Connection connection = getConnection();
  3. try {
  4. String sql = "UPDATE hits SET counter = counter + 1";
  5. PreparedStatement stmt = connection.prepareStatement(sql);
  6. stmt.executeUpdate();
  7. } catch (SQLException e) {
  8. e.printStackTrace();
  9. } finally {
  10. closeConnection(connection);
  11. }
  12. }
  13.  
  14. private void getHitCounterImage(HttpServletRequest req,
  15. HttpServletResponse res)
  16. throws IOException {
  17. Connection connection = getConnection();
  18. String hits = "";
  19. try {
  20. String sql = "SELECT counter FROM hits";
  21. PreparedStatement stmt = connection.prepareStatement(sql);
  22. ResultSet rs = stmt.executeQuery();
  23. while (rs.next()) {
  24. hits = rs.getString("counter");
  25. }
  26.  
  27. } catch (SQLException e) {
  28. e.printStackTrace();
  29. } finally {
  30. closeConnection(connection);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement