달력

112024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p></p>
 * @author Lee Jeong Hak(pluggers@naver.com)
 * @version $Revision: 1.2 $ $Date: 2004/05/06 01:27:53 $

 *  ResultSet을 컬렛션으로 반환
 */
public class RsToCollection {

    private int rsCount;
    private List rsList = new ArrayList();
    private ResultSet rs = null;

    /**
     * 
     */
    public RsToCollection(ResultSet rs) {
        this.rs = rs;
    }

    /**
     * @param rs
     * @return
     * @throws SQLException
     */
    private Object doCreateRow(ResultSet rs) throws SQLException {
        Map result = new HashMap();
        ResultSetMetaData rsmd = rs.getMetaData();
        int count = rsmd.getColumnCount();
        for (int i = 1; i <= count; i++) {
            String label = rsmd.getColumnLabel(i);
            Object value = rs.getObject(i);
            if (label != null && value != null) {
                result.put(label.toUpperCase(), value);
            }
        }
        return result;
    }
    /**
     * @param rs
     * @return
     */
    public List getRsList() {
        try {
            while (rs.next()) {
                Object obj = doCreateRow(rs);
                if (obj instanceof Object[]) {
                    for (int i = 0; i < ((Object[]) obj).length; i++) {
                        rsList.add(((Object[]) obj)[i]);
                    }
                } else {
                    rsList.add(obj);
                }
            }
            rsCount = rsList.size();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rsList;
    }
    /**
     * @return
     */
    public Map getMapList(ResultSet rs) {
        getRsList();
        return (Map) rsList.get(0);
    }
    /**
     * @return
     */
    public int getRsCount() {
        return rsCount;
    }

    /**
     * @param i
     */
    public void setRsCount(int i) {
        rsCount = i;
    }

}

'Dev Language > JAVA' 카테고리의 다른 글

숫자형식 포멧 방법  (0) 2017.07.13
AES, SHA 암호화 1, JAVA  (0) 2017.03.30
AB 파일 압축풀기  (2) 2016.04.20
Eclipse 성능개선 최적화  (0) 2016.02.12
Log4j 로 쿼리 로그 깔금 하게 보기  (0) 2016.02.12
Posted by 타카스 류지
|