All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class ibs.util.DbUtils

java.lang.Object
   |
   +----ibs.util.DbUtils

public class DbUtils
extends Object
This class provides certain database utilities that helps eliminate coding of repetative tasks for dealing with a ResultSet.

See Also:
ResultSet, ResultSetMetaData

Constructor Index

 o DbUtils()

Method Index

 o columnsToStringArray(ResultSet)
Generates a String array of column names for the given result set.
 o getColumnCount(ResultSet)
Returns column count for the given result set.
 o nextRecordToStringArray(ResultSet)
Generates a String array of record field value for the next record in the given result set.
 o printResultSet(ResultSet, PrintWriter)
Prints result set contents to the given PrintWriter.
 o printResultSet(ResultSet, PrintWriter, boolean)
Prints result set contents to the given PrintWriter.
 o printResultSetColumns(ResultSet, PrintWriter)
Prints result set column names to the given PrintWriter.
 o printResultSetColumns(ResultSetMetaData, PrintWriter)
Prints result set column names to the given PrintWriter.

Constructors

 o DbUtils
 public DbUtils()

Methods

 o printResultSet
 public void printResultSet(ResultSet rs,
                            PrintWriter pw) throws SQLException
Prints result set contents to the given PrintWriter. Primarily this will be helpful during development environment where you may wish to see the contents of the resultset or its column names on your screen. Result set will closed automatically at the end.

To get column names displayed on your standard output, just instantiate a PrintWriter object as new PrintWriter(System.out) and pass it to this method.

Parameters:
md - A ResultSet object.
pw - A PrintWriter where contents should be printed.
Throws: SQLException
In case of any sql error ...
 o printResultSet
 public void printResultSet(ResultSet rs,
                            PrintWriter pw,
                            boolean close_at_end) throws SQLException
Prints result set contents to the given PrintWriter. Primarily this will be helpful during development environment where you may wish to see the contents of the resultset or its column names on your screen.

To get column names displayed on your standard output, just instantiate a PrintWriter object as new PrintWriter(System.out) and pass it to this method.

Parameters:
md - A ResultSet object.
pw - A PrintWriter where contents should be printed.
close_at_end - If you wish not to close the resultset at the end, set this to 'true' By default this is 'false' and result set will be closed automatically.
Throws: SQLException
In case of any sql error ...
 o getColumnCount
 public int getColumnCount(ResultSet rs) throws SQLException
Returns column count for the given result set. Column count represents the number of column that formed a record in the result set.

Parameters:
rs - A ResultSet object.
 o printResultSetColumns
 public void printResultSetColumns(ResultSet rs,
                                   PrintWriter pw) throws SQLException
Prints result set column names to the given PrintWriter. Primarily this will be helpful during development environment where you may wish to see the contents of the resultset or its column names on your screen.

To get column names displayed on your standard output, just instantiate a PrintWriter object as new PrintWriter(System.out) and pass it to this method.
NOTE: In some cases, you may have to construct a PrintWriter object with a 'true' argument to set it to auto flush.

Parameters:
rs - A ResultSet object.
pw - A PrintWriter where contents should be printed.
Throws: SQLException
In case of any sql error ...
 o printResultSetColumns
 public void printResultSetColumns(ResultSetMetaData md,
                                   PrintWriter pw) throws SQLException
Prints result set column names to the given PrintWriter. Primarily this will be helpful during development environment where you may wish to see the contents of the resultset or its column names on your screen.

To get column names displayed on your standard output, just instantiate a PrintWriter object as new PrintWriter(System.out) and pass it to this method.
NOTE: In some cases, you may have to construct a PrintWriter object with a 'true' argument to set it to auto flush.

Parameters:
md - A ResultSetMetaData object.
pw - A PrintWriter where contents should be printed.
Throws: SQLException
In case of any sql error ...
 o columnsToStringArray
 public String[] columnsToStringArray(ResultSet rs) throws SQLException
Generates a String array of column names for the given result set.

Parameters:
rs - A ResultSet object
Returns:
A String array containg result set column names.
 o nextRecordToStringArray
 public String[] nextRecordToStringArray(ResultSet rs) throws SQLException
Generates a String array of record field value for the next record in the given result set.

Parameters:
rs - A ResultSet object
Returns:
A String array containg field values for the next record in the ResultSet. Returns null if there are no more records ( call to next() returns false. );

All Packages  Class Hierarchy  This Package  Previous  Next  Index