예제 #1
0
  public static Cuisine getCuisineByCid(String cid) {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE " + CID + " = '" + cid + "'";

    System.out.println(sql);

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Cuisine cuisine = null;

    try {
      conn = DBUtil.getConnectionFromDataSource();
      pstmt = conn.prepareStatement(sql);
      rs = pstmt.executeQuery();

      if (rs.next()) {
        cuisine = constructCuisineFromResultSet(rs);
      }
      return cuisine;
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        rs.close();
        pstmt.close();
        conn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return null;
  }
예제 #2
0
  public static List<Cuisine> searchCuisineByName(String cname) {
    List<Cuisine> cuisineList = new ArrayList<Cuisine>();

    String sql = "SELECT * FROM Cuisine_types WHERE UPPER(ct_name) LIKE UPPER('%" + cname + "%')";
    System.out.println(sql);

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {
      conn = DBUtil.getConnectionFromDataSource();
      pstmt = conn.prepareStatement(sql);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        Cuisine cuisine = constructCuisineFromResultSet(rs);
        cuisineList.add(cuisine);
      }
      return cuisineList;
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        rs.close();
        pstmt.close();
        conn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return null;
  }
예제 #3
0
  public static List<Cuisine> getAllCuisines() {
    List<Cuisine> cuisineList = new ArrayList<Cuisine>();

    String sql = "SELECT * FROM " + TABLE_NAME;
    System.out.println(sql);

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {
      conn = DBUtil.getConnectionFromDataSource();
      pstmt = conn.prepareStatement(sql);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        Cuisine cuisine = constructCuisineFromResultSet(rs);
        cuisineList.add(cuisine);
      }
      return cuisineList;
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        rs.close();
        pstmt.close();
        conn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return null;
  }