Пример #1
0
  @Override
  public Object getElementById(String id) {
    Object obj = null;
    try {

      pstmt = conn.prepareStatement("select * from THEME_MESSAGE " + "where THEME_MESSAGE_ID = ?");
      pstmt.setString(1, id);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        bean = new ThemeBean();
        bean.setId(rs.getInt("bean_MESSAGE_ID"));
        bean.setGroupId(rs.getInt("GROUP_ID"));
        bean.setOrderNo(rs.getInt("ORDER_NO"));
        bean.setLevel(rs.getInt("LEVEL"));
        bean.setParentId(rs.getInt("PARENT_ID"));
        bean.setRegister(rs.getTimestamp("REGISTER"));
        bean.setName(rs.getString("NAME"));
        bean.setEmail(rs.getString("EMAIL"));
        bean.setImage(rs.getString("IMAGE"));
        bean.setPassword(rs.getString("PASSWORD"));
        bean.setTitle(rs.getString("TITLE"));

        pstmt =
            conn.prepareStatement(
                "select CONTENT from THEME_CONTENT " + "where THEME_MESSAGE_ID = ?");
        pstmt.setString(1, id);
        rs = pstmt.executeQuery();
        /*   if (rs.next()) {
        Reader reader = null;
        try {
            reader = rs.getCharacterStream("CONTENT");
            char[] buff = new char[512];
            int len = -1;
            StringBuffer buffer = new StringBuffer(512);
            while( (len = reader.read(buff)) != -1) {
                buffer.append(buff, 0, len);
            }
            bean.setContent(buffer.toString());
        */
      }
    } catch (SQLException ex) {
      ex.printStackTrace();

    } finally {
      if (rs != null)
        try {
          rs.close();
        } catch (SQLException ex) {
        }
      if (pstmt != null)
        try {
          pstmt.close();
        } catch (SQLException ex) {
        }
    }
    return obj;
  }
Пример #2
0
  @Override
  public List<Object> list() {
    List<Object> list = new ArrayList<Object>();
    int endRow = 0, startRow = 0;
    try {

      String sql = "select * from THEME_MESSAGE order by GROUP_ID desc, ORDER_NO asc limit ?, ?";

      pstmt = conn.prepareStatement(sql);
      /*   Iterator keyIter = valueMap.keySet().iterator();
      while(keyIter.hasNext()) {
          Integer key = (Integer)keyIter.next();
          Object obj = valueMap.get(key);
          if (obj instanceof String) {
              pstmtMessage.setString(key.intValue(), (String)obj);
          } else if (obj instanceof Integer) {
              pstmtMessage.setInt(key.intValue(),
                                  ((Integer)obj).intValue());
          } else if (obj instanceof Timestamp) {
              pstmtMessage.setTimestamp(key.intValue(),
                                       (Timestamp)obj);
          }
      }
      */
      /*  pstmt.setInt(valueMap.size()+1, startRow);
      pstmt.setInt(valueMap.size()+2, endRow-startRow+1);
      */
      rs = pstmt.executeQuery();
      if (rs.next()) {
        list = new java.util.ArrayList(endRow - startRow + 1);

        do {
          ThemeBean bean = new ThemeBean();
          bean.setId(rs.getInt("bean_MESSAGE_ID"));
          bean.setGroupId(rs.getInt("GROUP_ID"));
          bean.setOrderNo(rs.getInt("ORDER_NO"));
          bean.setLevel(rs.getInt("LEVEL"));
          bean.setParentId(rs.getInt("PARENT_ID"));
          bean.setRegister(rs.getTimestamp("REGISTER"));
          bean.setName(rs.getString("NAME"));
          bean.setEmail(rs.getString("EMAIL"));
          bean.setImage(rs.getString("IMAGE"));
          bean.setPassword(rs.getString("PASSWORD"));
          bean.setTitle(rs.getString("TITLE"));
          list.add(bean);
        } while (rs.next());
      }

    } catch (SQLException ex) {
      ex.printStackTrace();
    } finally {

    }

    return list;
  }