Package com.opencsv
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 int
protected String
protected String
(package private) static final String
(package private) static final String
private static final String
protected NumberFormat
protected NumberFormat
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate String
applyFormatter
(NumberFormat formatter, Number value) String[]
Returns the column names from the ResultSet.private String
getColumnValue
(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 String
handleClob
(ResultSet rs, int colIndex) retrieves the data out of a CLOBprotected String
handleDate
(ResultSet rs, int colIndex, String dateFormatString) retrieves an date from a result setprotected String
handleNClob
(ResultSet rs, int colIndex) retrieves the data out of a NCLOBprotected String
handleNVarChar
(ResultSet rs, int colIndex, boolean trim) retrieves the data from an NVarChar in a result setprotected String
handleTimestamp
(Timestamp timestamp, String timestampFormatString) The formatted timestamp.protected String
handleVarChar
(ResultSet rs, int colIndex, boolean trim) retrieves the data from an VarChar in a result setvoid
setDateFormat
(String dateFormat) Set a default date format pattern that will be used by the service.void
setDateTimeFormat
(String dateTimeFormat) Set a default date time format pattern that will be used by the service.void
setFloatingPointFormat
(NumberFormat format) Set a default number formatter for integer numbers that will be used by the service.void
setIntegerFormat
(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:ResultSetHelper
Returns the column names from the ResultSet.- Specified by:
getColumnNames
in interfaceResultSetHelper
- Parameters:
rs
- ResultSet- Returns:
- String array containing the column names.
- Throws:
SQLException
- Thrown by the ResultSet.
-
getColumnValues
Description copied from interface:ResultSetHelper
Returns the column values from the result set.- Specified by:
getColumnValues
in 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:ResultSetHelper
Returns the column values from the result set with the values trimmed if desired.- Specified by:
getColumnValues
in 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:ResultSetHelper
Returns 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:
getColumnValues
in 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
The formatted timestamp.- Parameters:
timestamp
- Timestamp read from resultsettimestampFormatString
- Format string- Returns:
- Formatted time stamp.
-
getColumnValue
private String getColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString, String timestampFormatString) throws SQLException, IOException - Throws:
SQLException
IOException
-
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:
SQLException
IOException
-
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:
SQLException
IOException
-