Package com.opencsv
Class ResultSetHelperService
- java.lang.Object
-
- com.opencsv.ResultSetHelperService
-
- All Implemented Interfaces:
ResultSetHelper
- Direct Known Subclasses:
ResultSetColumnNameHelperService
public class ResultSetHelperService extends java.lang.Object implements ResultSetHelper
Helper class for processing JDBC ResultSet objects.
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
CLOBBUFFERSIZE
protected java.lang.String
dateFormat
protected java.lang.String
dateTimeFormat
(package private) static java.lang.String
DEFAULT_DATE_FORMAT
(package private) static java.lang.String
DEFAULT_TIMESTAMP_FORMAT
private static java.lang.String
DEFAULT_VALUE
protected java.text.NumberFormat
floatingPointFormat
protected java.text.NumberFormat
integerFormat
-
Constructor Summary
Constructors Constructor Description ResultSetHelperService()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
applyFormatter(java.text.NumberFormat formatter, java.lang.Number value)
java.lang.String[]
getColumnNames(java.sql.ResultSet rs)
Returns the column names from the ResultSet.private java.lang.String
getColumnValue(java.sql.ResultSet rs, int colType, int colIndex, boolean trim, java.lang.String dateFormatString, java.lang.String timestampFormatString)
java.lang.String[]
getColumnValues(java.sql.ResultSet rs)
Returns the column values from the result set.java.lang.String[]
getColumnValues(java.sql.ResultSet rs, boolean trim)
Returns the column values from the result set with the values trimmed if desired.java.lang.String[]
getColumnValues(java.sql.ResultSet rs, boolean trim, java.lang.String dateFormatString, java.lang.String timeFormatString)
Returns the column values from the result set with the values trimmed if desired.protected java.lang.String
handleClob(java.sql.ResultSet rs, int colIndex)
retrieves the data out of a CLOBprotected java.lang.String
handleDate(java.sql.ResultSet rs, int colIndex, java.lang.String dateFormatString)
retrieves an date from a result setprotected java.lang.String
handleNClob(java.sql.ResultSet rs, int colIndex)
retrieves the data out of a NCLOBprotected java.lang.String
handleNVarChar(java.sql.ResultSet rs, int colIndex, boolean trim)
retrieves the data from an NVarChar in a result setprotected java.lang.String
handleTimestamp(java.sql.Timestamp timestamp, java.lang.String timestampFormatString)
The formatted timestamp.protected java.lang.String
handleVarChar(java.sql.ResultSet rs, int colIndex, boolean trim)
retrieves the data from an VarChar in a result setvoid
setDateFormat(java.lang.String dateFormat)
Set a default date format pattern that will be used by the service.void
setDateTimeFormat(java.lang.String dateTimeFormat)
Set a default date time format pattern that will be used by the service.void
setFloatingPointFormat(java.text.NumberFormat format)
Set a default number formatter for integer numbers that will be used by the service.void
setIntegerFormat(java.text.NumberFormat format)
Set a default number formatter for floating point numbers that will be used by the service.
-
-
-
Field Detail
-
CLOBBUFFERSIZE
protected static final int CLOBBUFFERSIZE
- See Also:
- Constant Field Values
-
DEFAULT_DATE_FORMAT
static final java.lang.String DEFAULT_DATE_FORMAT
- See Also:
- Constant Field Values
-
DEFAULT_TIMESTAMP_FORMAT
static final java.lang.String DEFAULT_TIMESTAMP_FORMAT
- See Also:
- Constant Field Values
-
DEFAULT_VALUE
private static final java.lang.String DEFAULT_VALUE
- See Also:
- Constant Field Values
-
dateFormat
protected java.lang.String dateFormat
-
dateTimeFormat
protected java.lang.String dateTimeFormat
-
integerFormat
protected java.text.NumberFormat integerFormat
-
floatingPointFormat
protected java.text.NumberFormat floatingPointFormat
-
-
Method Detail
-
setDateFormat
public void setDateFormat(java.lang.String dateFormat)
Set a default date format pattern that will be used by the service.- Parameters:
dateFormat
- Desired date format
-
setDateTimeFormat
public void setDateTimeFormat(java.lang.String dateTimeFormat)
Set a default date time format pattern that will be used by the service.- Parameters:
dateTimeFormat
- Desired date time format
-
setIntegerFormat
public void setIntegerFormat(java.text.NumberFormat format)
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
public void setFloatingPointFormat(java.text.NumberFormat format)
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
public java.lang.String[] getColumnNames(java.sql.ResultSet rs) throws java.sql.SQLException
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:
java.sql.SQLException
- Thrown by the ResultSet.
-
getColumnValues
public java.lang.String[] getColumnValues(java.sql.ResultSet rs) throws java.sql.SQLException, java.io.IOException
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:
java.sql.SQLException
- Thrown by the ResultSet.java.io.IOException
- Thrown by the ResultSet.
-
getColumnValues
public java.lang.String[] getColumnValues(java.sql.ResultSet rs, boolean trim) throws java.sql.SQLException, java.io.IOException
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:
java.sql.SQLException
- Thrown by the ResultSet.java.io.IOException
- Thrown by the ResultSet.
-
getColumnValues
public java.lang.String[] getColumnValues(java.sql.ResultSet rs, boolean trim, java.lang.String dateFormatString, java.lang.String timeFormatString) throws java.sql.SQLException, java.io.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:
java.sql.SQLException
- Thrown by the ResultSet.java.io.IOException
- Thrown by the ResultSet.
-
handleTimestamp
protected java.lang.String handleTimestamp(java.sql.Timestamp timestamp, java.lang.String timestampFormatString)
The formatted timestamp.- Parameters:
timestamp
- Timestamp read from resultsettimestampFormatString
- Format string- Returns:
- Formatted time stamp.
-
getColumnValue
private java.lang.String getColumnValue(java.sql.ResultSet rs, int colType, int colIndex, boolean trim, java.lang.String dateFormatString, java.lang.String timestampFormatString) throws java.sql.SQLException, java.io.IOException
- Throws:
java.sql.SQLException
java.io.IOException
-
applyFormatter
private java.lang.String applyFormatter(java.text.NumberFormat formatter, java.lang.Number value)
-
handleVarChar
protected java.lang.String handleVarChar(java.sql.ResultSet rs, int colIndex, boolean trim) throws java.sql.SQLException
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:
java.sql.SQLException
-
handleNVarChar
protected java.lang.String handleNVarChar(java.sql.ResultSet rs, int colIndex, boolean trim) throws java.sql.SQLException
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:
java.sql.SQLException
-
handleDate
protected java.lang.String handleDate(java.sql.ResultSet rs, int colIndex, java.lang.String dateFormatString) throws java.sql.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:
java.sql.SQLException
-
handleClob
protected java.lang.String handleClob(java.sql.ResultSet rs, int colIndex) throws java.sql.SQLException, java.io.IOException
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:
java.sql.SQLException
java.io.IOException
-
handleNClob
protected java.lang.String handleNClob(java.sql.ResultSet rs, int colIndex) throws java.sql.SQLException, java.io.IOException
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:
java.sql.SQLException
java.io.IOException
-
-