com.fdsapi
Class ResultSetUtils

java.lang.Object
  |
  +--com.fdsapi.ResultSetUtils

public class ResultSetUtils
extends java.lang.Object

Provides various methods for manipulating ResultSets such as converting them to Lists, and 2 dimensional arrays.



View Code


Constructor Summary
protected ResultSetUtils()
           
 
Method Summary
 java.lang.String[] convert(java.lang.Object[] arr)
          Calls toString() on all elements of an Object[] array and converts all elements to a String[] array.
 java.lang.String[][] convert(java.lang.Object[][] arr)
          Calls toString() on all elements of an Object[][] array and converts all elements to a String[][] array.
static ResultSetUtils createInstance()
           
 java.lang.String[] getColumnNames(java.sql.ResultSetMetaData resultSetMetaData)
          The following method returns an array of strings containing the column names for a given ResultSetMetaData object.
 java.lang.String[] getColumnNames(java.sql.ResultSetMetaData resultSetMetaData, int[] returnCols)
          The following method returns an array of strings containing the column names for a given ResultSetMetaData object.
 java.lang.Object[][] listToObjectArray(java.util.List list)
          The following method converts an List, into a two dimensional string array.
static void main(java.lang.String[] args)
           
 void objectArrayToList(java.util.List list, java.lang.Object[][] data)
          The following method converts an Object[][] to a List where each entry in the list is a row (i.e.
 void objectArrayToMap(java.util.Map map, java.lang.Object[][] data)
          The following method converts an Object[][] to a Map of object keys and values using an instance of Map.
 void resultSetMetaDataToList(java.util.List list, java.sql.ResultSet resultSet)
          The following method returns a List containing the ResultSetMetaData column names.
 void resultSetToList(java.util.List list, java.sql.ResultSet resultSet)
          The following method returns a List containing the ResultSet data.
 void resultSetToMap(java.util.Map map, java.sql.ResultSet resultSet)
          The following method converts ResultSet data to a Map of object keys and values using an instance of HashMap.
 java.lang.Object[][] resultSetToObjectArray(java.sql.ResultSet resultSet)
          The following method simply takes the ResultSet and converts it to a two dimensional array of Objects containing data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSetUtils

protected ResultSetUtils()
Method Detail

createInstance

public static ResultSetUtils createInstance()

resultSetToList

public void resultSetToList(java.util.List list,
                            java.sql.ResultSet resultSet)
                     throws java.sql.SQLException
The following method returns a List containing the ResultSet data. Rows contain ResultSet rows as object arrays. The method getRowData() converts ResultSet row data into an object array.

java.sql.SQLException

resultSetMetaDataToList

public void resultSetMetaDataToList(java.util.List list,
                                    java.sql.ResultSet resultSet)
                             throws java.sql.SQLException
The following method returns a List containing the ResultSetMetaData column names. There is only 1 row in the List and it will always contain a string array of the column names.

java.sql.SQLException

resultSetToMap

public void resultSetToMap(java.util.Map map,
                           java.sql.ResultSet resultSet)
                    throws java.sql.SQLException

The following method converts ResultSet data to a Map of object keys and values using an instance of HashMap.

The first column in the ResultSet supplies the key, the second column the value. If the ResultSet contains more than two columns then subsequent columns are ignored. If the ResultSet supplies only one column then an SQLException is thrown. The ResultSet values are converted to objects using the getRowData() method which converts a ResultSet row into an array of objects.

java.sql.SQLException

objectArrayToMap

public void objectArrayToMap(java.util.Map map,
                             java.lang.Object[][] data)

The following method converts an Object[][] to a Map of object keys and values using an instance of Map.

The first column in the array supplies the key, the second column the value. If the array contains more than two columns then subsequent columns are ignored. If the array supplies only one column then a RuntimeException is thrown. This method may be used to convert the data in a ResultSetConverter to a map.


objectArrayToList

public void objectArrayToList(java.util.List list,
                              java.lang.Object[][] data)

The following method converts an Object[][] to a List where each entry in the list is a row (i.e. a one dimensional array Object[])

This list add/concatenate multiple arrays by making multiple calls while passing in the same list


listToObjectArray

public java.lang.Object[][] listToObjectArray(java.util.List list)

The following method converts an List, into a two dimensional string array. This array must be be allocated before it can be passed as an argument to the List toArray() method. The method assumes the list contains one dimensional arrays.

The first dimension is the row data.

The second dimension is the columns. The number of coluns is obtained by length of the string array in the first element of the List since:

1. The length of all arrays in the List must be the same.


resultSetToObjectArray

public java.lang.Object[][] resultSetToObjectArray(java.sql.ResultSet resultSet)
                                            throws java.sql.SQLException
The following method simply takes the ResultSet and converts it to a two dimensional array of Objects containing data.

java.sql.SQLException

getColumnNames

public java.lang.String[] getColumnNames(java.sql.ResultSetMetaData resultSetMetaData)
                                  throws java.sql.SQLException
The following method returns an array of strings containing the column names for a given ResultSetMetaData object.

java.sql.SQLException

getColumnNames

public java.lang.String[] getColumnNames(java.sql.ResultSetMetaData resultSetMetaData,
                                         int[] returnCols)
                                  throws java.sql.SQLException
The following method returns an array of strings containing the column names for a given ResultSetMetaData object. The returnCols array is the columns to return.

java.sql.SQLException

convert

public java.lang.String[][] convert(java.lang.Object[][] arr)
Calls toString() on all elements of an Object[][] array and converts all elements to a String[][] array.


convert

public java.lang.String[] convert(java.lang.Object[] arr)
Calls toString() on all elements of an Object[] array and converts all elements to a String[] array.


main

public static void main(java.lang.String[] args)