01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * See the License for the specific language governing rights and
10: * limitations under the License.
11: *
12: * The Initial Developer of the Original Code is Simulacra Media Ltd.
13: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14: *
15: * All Rights Reserved.
16: *
17: * Contributor(s):
18: */
19: package org.openharmonise.commons.dsi;
20:
21: import java.sql.*;
22: import java.util.*;
23:
24: /**
25: * Utility class for obtaining metadata from a result set in a convenient
26: * form.
27: *
28: * @author Michael Bell
29: * @version $Revision: 1.1 $
30: *
31: */
32: public class ResultSetUtil {
33:
34: /**
35: * Private constructor so that class cannot be instantiated.
36: *
37: */
38: private ResultSetUtil() {
39:
40: }
41:
42: /**
43: * Returns the list of column names held within the given result set
44: * metadata.
45: *
46: * @param rs the result set
47: * @return the list of column names
48: * @throws SQLException if an error occurs accessing the metadata of the
49: * result set
50: */
51: static public List getResultSetColumns(ResultSet rs)
52: throws SQLException {
53: ArrayList cols = new ArrayList();
54:
55: ResultSetMetaData rsmeta = rs.getMetaData();
56:
57: int nCols = rsmeta.getColumnCount();
58:
59: for (int i = 1; i <= nCols; i++) {
60: cols.add(rsmeta.getColumnName(i));
61: }
62:
63: return cols;
64: }
65: }
|