Package com.opencsv

Class ResultSetHelperService

java.lang.Object
com.opencsv.ResultSetHelperService
All Implemented Interfaces:
ResultSetHelper
Direct Known Subclasses:
ResultSetColumnNameHelperService

public class ResultSetHelperService extends Object implements ResultSetHelper
Helper class for processing JDBC ResultSet objects.
  • Field Details

  • Constructor Details

    • ResultSetHelperService

      public ResultSetHelperService()
      Default constructor.
  • Method Details

    • setDateFormat

      public void setDateFormat(String dateFormat)
      Set a default date format pattern that will be used by the service.
      Parameters:
      dateFormat - Desired date format
    • setDateTimeFormat

      public void setDateTimeFormat(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(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(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 String[] getColumnNames(ResultSet rs) throws SQLException
      Description copied from interface: ResultSetHelper
      Returns the column names from the ResultSet.
      Specified by:
      getColumnNames in interface ResultSetHelper
      Parameters:
      rs - ResultSet
      Returns:
      String array containing the column names.
      Throws:
      SQLException - Thrown by the ResultSet.
    • getColumnValues

      public String[] getColumnValues(ResultSet rs) throws SQLException, IOException
      Description copied from interface: ResultSetHelper
      Returns the column values from the result set.
      Specified by:
      getColumnValues in interface ResultSetHelper
      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

      public String[] getColumnValues(ResultSet rs, boolean trim) throws SQLException, IOException
      Description copied from interface: ResultSetHelper
      Returns the column values from the result set with the values trimmed if desired.
      Specified by:
      getColumnValues in interface ResultSetHelper
      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 interface ResultSetHelper
      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

      protected String handleTimestamp(Timestamp timestamp, String timestampFormatString)
      The formatted timestamp.
      Parameters:
      timestamp - Timestamp read from resultset
      timestampFormatString - 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

      private String applyFormatter(NumberFormat formatter, Number value)
    • handleVarChar

      protected String handleVarChar(ResultSet rs, int colIndex, boolean trim) throws SQLException
      retrieves the data from an VarChar in a result set
      Parameters:
      rs - - result set
      colIndex - - column location of the data in the result set
      trim - - should the value be trimmed before being returned
      Returns:
      a string representing the VarChar from the result set
      Throws:
      SQLException
    • handleNVarChar

      protected String handleNVarChar(ResultSet rs, int colIndex, boolean trim) throws SQLException
      retrieves the data from an NVarChar in a result set
      Parameters:
      rs - - result set
      colIndex - - column location of the data in the result set
      trim - - 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 set
      colIndex - - column location of the data in the result set
      dateFormatString - - desired format of the date
      Returns:
      - a string representing the data from the result set in the format set in dateFomratString.
      Throws:
      SQLException
    • handleClob

      protected String handleClob(ResultSet rs, int colIndex) throws SQLException, IOException
      retrieves the data out of a CLOB
      Parameters:
      rs - - result set
      colIndex - - column location of the data in the result set
      Returns:
      the data in the Clob as a string.
      Throws:
      SQLException
      IOException
    • handleNClob

      protected String handleNClob(ResultSet rs, int colIndex) throws SQLException, IOException
      retrieves the data out of a NCLOB
      Parameters:
      rs - - result set
      colIndex - - column location of the data in the result set
      Returns:
      the data in the NCLOB as a string.
      Throws:
      SQLException
      IOException