Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. Connection conn = null;
  2. Statement stmt = null;
  3. PreparedStatement pstmt = null;
  4. ResultSet rs = null;
  5.  
  6.  
  7. public ArrayList<Coffee> getAllCoffees()
  8. {
  9. try
  10. {
  11. conn = ConnectionPool.getPool().getConnection();
  12. String sql = "SELECT * FROM coffees";
  13. stmt = conn.createStatement();
  14. rs = stmt.executeQuery(sql);
  15. ArrayList<Coffee> coffeeList = new ArrayList<Coffee>();
  16. Coffee coffee = null;
  17. while(rs.next())
  18. {
  19. coffee = new Coffee();
  20. coffee.setCof_name(rs.getString("cof_name"));
  21. coffee.setSup_id(rs.getInt("sup_id"));
  22. coffee.setPrice(rs.getDouble("price"));
  23. coffee.setSales(rs.getDouble("sales"));
  24. coffee.setTotal(rs.getDouble("total"));
  25. coffeeList.add(coffee);
  26. }
  27. return coffeeList;
  28. }
  29. catch(Exception ex)
  30. {
  31. ex.printStackTrace();
  32. throw new RuntimeException();
  33. }
  34. finally
  35. {
  36. try
  37. {
  38. if(rs != null)
  39. {
  40. rs.close();
  41. }
  42. if(stmt != null)
  43. {
  44. stmt.close();
  45. }
  46. if(conn != null)
  47. {
  48. ConnectionPool.getPool().releaseConnection(conn);
  49. }
  50. }
  51. catch(Exception ex)
  52. {
  53. ex.printStackTrace();
  54. throw new RuntimeException(ex);
  55. }
  56. }
  57. }
  58.  
  59. return null:
  60.  
  61. catch(Exception ex)
  62. {
  63. ex.printStackTrace();
  64. //throw new RuntimeException();
  65.  
  66. return new ArrayList<Coffee>() ;
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement