public static ArrayList<HotelFacilitiesEntities> retrieveByMemberID(String membershipNo) { HotelFacilitiesEntities hf1 = null; Statement stmt = null; String searchQuery = "select * from hotelfacilities where membershipNo = '" + membershipNo + "'"; ArrayList<HotelFacilitiesEntities> hfList = new ArrayList<HotelFacilitiesEntities>(); try { // connect to DB currentCon = DBConnectionManager.getConnection(); stmt = currentCon.createStatement(); rs = stmt.executeQuery(searchQuery); while (rs.next()) { String type = rs.getString("type"); String date = rs.getString("date"); String name = rs.getString("name"); String startTime = rs.getString("startTime"); String endTime = rs.getString("endTime"); hf1 = new HotelFacilitiesEntities(); hf1.setType(type); hf1.setDate(date); hf1.setName(name); hf1.setStartTime(startTime); hf1.setEndTime(endTime); hfList.add(hf1); } } catch (Exception e) { e.printStackTrace(); } return hfList; }
public static void hotelFacilities(HotelFacilitiesEntities hf) { Statement stmt = null; // get the last member ID try { // query for inserting into the table currentCon = DBConnectionManager.getConnection(); stmt = currentCon.createStatement(); String query = "insert into hotelfacilities(membershipNo,status,endTime,startTime,name,date,type) values(?,?,?,?,?,?,?)"; pstmt = currentCon.prepareStatement(query); // inserting values pstmt.setString(1, hf.getMembershipNo()); pstmt.setString(2, "true"); pstmt.setString(3, hf.getEndTime()); pstmt.setString(4, hf.getStartTime()); pstmt.setString(5, hf.getName()); pstmt.setString(6, hf.getDate()); pstmt.setString(7, hf.getType()); pstmt.executeUpdate(); } catch (Exception ex) { System.out.println("Registration failed: An Exception has occurred! " + ex); } // exception handling finally { if (rs != null) { try { rs.close(); } catch (Exception e) { } rs = null; } if (stmt != null) { try { stmt.close(); } catch (Exception e) { } stmt = null; } if (currentCon != null) { try { currentCon.close(); } catch (Exception e) { } currentCon = null; } } }