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 intCLOBBUFFERSIZEprotected java.lang.StringdateFormatprotected java.lang.StringdateTimeFormat(package private) static java.lang.StringDEFAULT_DATE_FORMAT(package private) static java.lang.StringDEFAULT_TIMESTAMP_FORMATprivate static java.lang.StringDEFAULT_VALUEprotected java.text.NumberFormatfloatingPointFormatprotected java.text.NumberFormatintegerFormat
-
Constructor Summary
Constructors Constructor Description ResultSetHelperService()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringapplyFormatter(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.StringgetColumnValue(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.StringhandleClob(java.sql.ResultSet rs, int colIndex)retrieves the data out of a CLOBprotected java.lang.StringhandleDate(java.sql.ResultSet rs, int colIndex, java.lang.String dateFormatString)retrieves an date from a result setprotected java.lang.StringhandleNClob(java.sql.ResultSet rs, int colIndex)retrieves the data out of a NCLOBprotected java.lang.StringhandleNVarChar(java.sql.ResultSet rs, int colIndex, boolean trim)retrieves the data from an NVarChar in a result setprotected java.lang.StringhandleTimestamp(java.sql.Timestamp timestamp, java.lang.String timestampFormatString)The formatted timestamp.protected java.lang.StringhandleVarChar(java.sql.ResultSet rs, int colIndex, boolean trim)retrieves the data from an VarChar in a result setvoidsetDateFormat(java.lang.String dateFormat)Set a default date format pattern that will be used by the service.voidsetDateTimeFormat(java.lang.String dateTimeFormat)Set a default date time format pattern that will be used by the service.voidsetFloatingPointFormat(java.text.NumberFormat format)Set a default number formatter for integer numbers that will be used by the service.voidsetIntegerFormat(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.SQLExceptionDescription 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:
java.sql.SQLException- Thrown by the ResultSet.
-
getColumnValues
public java.lang.String[] getColumnValues(java.sql.ResultSet rs) throws java.sql.SQLException, java.io.IOExceptionDescription 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:
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.IOExceptionDescription 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:
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.IOExceptionDescription 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:
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.SQLExceptionjava.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.SQLExceptionretrieves 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.SQLExceptionretrieves 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.SQLExceptionretrieves 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.IOExceptionretrieves 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.SQLExceptionjava.io.IOException
-
handleNClob
protected java.lang.String handleNClob(java.sql.ResultSet rs, int colIndex) throws java.sql.SQLException, java.io.IOExceptionretrieves 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.SQLExceptionjava.io.IOException
-
-