com.bristle.javalib.sql
Class JDBCUtil
java.lang.Object
com.bristle.javalib.sql.JDBCUtil
public class JDBCUtil
- extends Object
This class contains utility routines for use with JDBC.
Usage:
- The typical scenario for using this class is:
String s = JDBCUtil.getColumnOrEmptyString(rs, strColumnName);
Assumptions:
Effects:
- None.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
$Log$
|
Nested Class Summary |
static class |
JDBCUtil.Tester
Each class contains a Tester inner class with a main() for easier
unit testing. |
JDBCUtil
public JDBCUtil()
getColumnOrEmptyString
public static String getColumnOrEmptyString(ResultSet rs,
String strColumnName)
throws SQLException
- Returns the specified column of the specified resultset, mapping
null values to the empty string.
- Parameters:
rs - ResultsetstrColumnName - Column name
- Returns:
- Column value (empty string if null).
- Throws:
SQLException - When an error occurs getting the column.
getRowCount
public static int getRowCount(ResultSet rs)
throws SQLException
- Returns the number of rows in the specified resultset.
Notes:
- This method requires a resultset that can be rewound. Therefore,
you can't use a TYPE_FORWARD_ONLY resultset. However, if you use
a TYPE_SCROLL_SENSITIVE or TYPE_SCROLL_INSENSITIVE resultset,
calling this method has the side effect of loading all rows of
the resultset into memory. (This happens automatically at the
call to last()). Therefore, do not use this method if you can't
afford the memory or the time to load all rows.
- Parameters:
rs - Resultset
- Returns:
- Row count.
- Throws:
SQLException - If the resultset is of type TYPE_FORWARD_ONLY.