Пример #1
0
 @Override
 public int find(String typeFeed) {
   int id = 0;
   try {
     Connection cn = null;
     try {
       JdbcConnection connection = JdbcConnection.getInstance();
       cn = connection.getConnection();
       PreparedStatement st = null;
       try {
         st = cn.prepareStatement("SELECT * FROM feed WHERE typeFeed = ?");
         st.setString(1, typeFeed);
         ResultSet rs = null;
         try {
           rs = st.executeQuery();
           if (rs.next()) {
             id = rs.getInt(1);
           }
         } 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 id;
 }
Пример #2
0
  @Override
  public void update(int id, Feed feed) {
    try {
      Connection cn = null;
      try {
        JdbcConnection connection = JdbcConnection.getInstance();
        cn = connection.getConnection();
        PreparedStatement st = null;
        try {
          st =
              cn.prepareStatement("UPDATE feed SET (typeFeed = ?, valueFeed = ?) WHERE idFeed = ?");
          st.setString(1, feed.name());
          st.setString(2, feed.getValueFeed());
          st.setInt(3, id);
          st.executeUpdate();

        } finally {
          if (st != null) st.close();
          st = null;
        }
      } finally {
        if (cn != null) cn.close();
        cn = null;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }