Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection conn = null;
- Statement stmt = null;
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- public ArrayList<Coffee> getAllCoffees()
- {
- try
- {
- conn = ConnectionPool.getPool().getConnection();
- String sql = "SELECT * FROM coffees";
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- ArrayList<Coffee> coffeeList = new ArrayList<Coffee>();
- Coffee coffee = null;
- while(rs.next())
- {
- coffee = new Coffee();
- coffee.setCof_name(rs.getString("cof_name"));
- coffee.setSup_id(rs.getInt("sup_id"));
- coffee.setPrice(rs.getDouble("price"));
- coffee.setSales(rs.getDouble("sales"));
- coffee.setTotal(rs.getDouble("total"));
- coffeeList.add(coffee);
- }
- return coffeeList;
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- throw new RuntimeException();
- }
- finally
- {
- try
- {
- if(rs != null)
- {
- rs.close();
- }
- if(stmt != null)
- {
- stmt.close();
- }
- if(conn != null)
- {
- ConnectionPool.getPool().releaseConnection(conn);
- }
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- throw new RuntimeException(ex);
- }
- }
- }
- return null:
- catch(Exception ex)
- {
- ex.printStackTrace();
- //throw new RuntimeException();
- return new ArrayList<Coffee>() ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement