KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > commons > dsi > ResultSetUtil


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * 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) throws SQLException {
52         ArrayList cols = new ArrayList();
53         
54         ResultSetMetaData rsmeta = rs.getMetaData();
55         
56         int nCols = rsmeta.getColumnCount();
57         
58         for(int i=1;i<=nCols;i++) {
59             cols.add(rsmeta.getColumnName(i));
60         }
61         
62         return cols;
63     }
64 }
65
Popular Tags