Class ResultSetHelperService
java.lang.Object
com.opencsv.ResultSetHelperService
- All Implemented Interfaces:
ResultSetHelper
- Direct Known Subclasses:
ResultSetColumnNameHelperService
Helper class for processing JDBC ResultSet objects.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected Stringprotected String(package private) static final String(package private) static final Stringprivate static final Stringprotected NumberFormatprotected NumberFormat -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringapplyFormatter(NumberFormat formatter, Number value) String[]Returns the column names from the ResultSet.private StringgetColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString, String timestampFormatString) String[]Returns the column values from the result set.String[]getColumnValues(ResultSet rs, boolean trim) Returns the column values from the result set with the values trimmed if desired.String[]getColumnValues(ResultSet rs, boolean trim, String dateFormatString, String timeFormatString) Returns the column values from the result set with the values trimmed if desired.protected StringhandleClob(ResultSet rs, int colIndex) retrieves the data out of a CLOBprotected StringhandleDate(ResultSet rs, int colIndex, String dateFormatString) retrieves an date from a result setprotected StringhandleNClob(ResultSet rs, int colIndex) retrieves the data out of a NCLOBprotected StringhandleNVarChar(ResultSet rs, int colIndex, boolean trim) retrieves the data from an NVarChar in a result setprotected StringhandleTimestamp(Timestamp timestamp, String timestampFormatString) The formatted timestamp.protected StringhandleVarChar(ResultSet rs, int colIndex, boolean trim) retrieves the data from an VarChar in a result setvoidsetDateFormat(String dateFormat) Set a default date format pattern that will be used by the service.voidsetDateTimeFormat(String dateTimeFormat) Set a default date time format pattern that will be used by the service.voidsetFloatingPointFormat(NumberFormat format) Set a default number formatter for integer numbers that will be used by the service.voidsetIntegerFormat(NumberFormat format) Set a default number formatter for floating point numbers that will be used by the service.
-
Field Details
-
CLOBBUFFERSIZE
protected static final int CLOBBUFFERSIZE- See Also:
-
DEFAULT_DATE_FORMAT
- See Also:
-
DEFAULT_TIMESTAMP_FORMAT
- See Also:
-
DEFAULT_VALUE
- See Also:
-
dateFormat
-
dateTimeFormat
-
integerFormat
-
floatingPointFormat
-
-
Constructor Details
-
ResultSetHelperService
public ResultSetHelperService()Default constructor.
-
-
Method Details
-
setDateFormat
Set a default date format pattern that will be used by the service.- Parameters:
dateFormat- Desired date format
-
setDateTimeFormat
Set a default date time format pattern that will be used by the service.- Parameters:
dateTimeFormat- Desired date time format
-
setIntegerFormat
Set a default number formatter for floating point numbers that will be used by the service.- Parameters:
format- Desired number format. Should not be null
-
setFloatingPointFormat
Set a default number formatter for integer numbers that will be used by the service.- Parameters:
format- Desired number format. Should not be null
-
getColumnNames
Description copied from interface:ResultSetHelperReturns the column names from the ResultSet.- Specified by:
getColumnNamesin interfaceResultSetHelper- Parameters:
rs- ResultSet- Returns:
- String array containing the column names.
- Throws:
SQLException- Thrown by the ResultSet.
-
getColumnValues
Description copied from interface:ResultSetHelperReturns the column values from the result set.- Specified by:
getColumnValuesin interfaceResultSetHelper- Parameters:
rs- The ResultSet containing the values.- Returns:
- String array containing the values.
- Throws:
SQLException- Thrown by the ResultSet.IOException- Thrown by the ResultSet.
-
getColumnValues
Description copied from interface:ResultSetHelperReturns the column values from the result set with the values trimmed if desired.- Specified by:
getColumnValuesin interfaceResultSetHelper- Parameters:
rs- The ResultSet containing the values.trim- Values should have white spaces trimmed.- Returns:
- String array containing the values.
- Throws:
SQLException- Thrown by the ResultSet.IOException- Thrown by the ResultSet.
-
getColumnValues
public String[] getColumnValues(ResultSet rs, boolean trim, String dateFormatString, String timeFormatString) throws SQLException, IOException Description copied from interface:ResultSetHelperReturns the column values from the result set with the values trimmed if desired. Also format the date and time columns based on the format strings passed in.- Specified by:
getColumnValuesin interfaceResultSetHelper- Parameters:
rs- The ResultSet containing the values.trim- Values should have white spaces trimmed.dateFormatString- Format string for dates.timeFormatString- Format string for timestamps.- Returns:
- String array containing the values.
- Throws:
SQLException- Thrown by the ResultSet.IOException- Thrown by the ResultSet.
-
handleTimestamp
-
getColumnValue
private String getColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString, String timestampFormatString) throws SQLException, IOException - Throws:
SQLExceptionIOException
-
applyFormatter
-
handleVarChar
retrieves the data from an VarChar in a result set- Parameters:
rs- - result setcolIndex- - column location of the data in the result settrim- - should the value be trimmed before being returned- Returns:
- a string representing the VarChar from the result set
- Throws:
SQLException
-
handleNVarChar
retrieves the data from an NVarChar in a result set- Parameters:
rs- - result setcolIndex- - column location of the data in the result settrim- - should the value be trimmed before being returned- Returns:
- a string representing the NVarChar from the result set
- Throws:
SQLException
-
handleDate
protected String handleDate(ResultSet rs, int colIndex, String dateFormatString) throws SQLException retrieves an date from a result set- Parameters:
rs- - result setcolIndex- - column location of the data in the result setdateFormatString- - desired format of the date- Returns:
- - a string representing the data from the result set in the format set in dateFomratString.
- Throws:
SQLException
-
handleClob
retrieves the data out of a CLOB- Parameters:
rs- - result setcolIndex- - column location of the data in the result set- Returns:
- the data in the Clob as a string.
- Throws:
SQLExceptionIOException
-
handleNClob
retrieves the data out of a NCLOB- Parameters:
rs- - result setcolIndex- - column location of the data in the result set- Returns:
- the data in the NCLOB as a string.
- Throws:
SQLExceptionIOException
-