Exemplo n.º 1
0
 @Override
 public Feed find(int id) {
   Feed feed = null;
   try {
     Connection cn = null;
     try {
       JdbcConnection connection = JdbcConnection.getInstance();
       cn = connection.getConnection();
       PreparedStatement st = null;
       try {
         st = cn.prepareStatement("SELECT * FROM feed WHERE idFeed = ?");
         st.setInt(1, id);
         ResultSet rs = null;
         try {
           rs = st.executeQuery();
           if (rs.next()) {
             feed = Feed.valueOf(rs.getString(2));
           }
         } finally {
           if (rs != null) rs.close();
           rs = null;
         }
       } finally {
         if (st != null) st.close();
         st = null;
       }
     } finally {
       if (cn != null) cn.close();
       cn = null;
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return feed;
 }
Exemplo n.º 2
0
  @Override
  public List<Feed> findAll() {
    List<Feed> feeds = new ArrayList<Feed>();

    try {
      Connection cn = null;
      try {
        cn = JdbcConnection.getInstance().getConnection();
        Statement st = null;
        try {
          st = cn.createStatement();
          ResultSet rs = null;
          try {
            rs = st.executeQuery("SELECT * FROM feed ");
            while (rs.next()) {
              feeds.add(Feed.valueOf(rs.getString(2)));
            }
          } finally {
            if (rs != null) rs.close();
            rs = null;
          }
        } finally {
          if (st != null) st.close();
          st = null;
        }
      } finally {
        if (cn != null) cn.close();
        cn = null;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return feeds;
  }