Class CsvResultSetWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, ICsvResultSetWriter, ICsvWriter

    public class CsvResultSetWriter
    extends AbstractCsvWriter
    implements ICsvResultSetWriter
    CsvResultSetWriter writes a CSV file by mapping each column of the ResultSet to a column in CSV file using the column names stored in ResultSetMetaData
    Since:
    2.4.0
    Author:
    SingularityFX
    • Constructor Detail

      • CsvResultSetWriter

        public CsvResultSetWriter​(java.io.Writer writer,
                                  CsvPreference preference)
        Constructs a new CsvResultSetWriter with the supplied Writer and CSV preferences. Note that the writer will be wrapped in a BufferedWriter before accessed.
        Parameters:
        writer - the writer
        preference - the CSV preferences
        Throws:
        java.lang.NullPointerException - if writer or preference are null
    • Method Detail

      • write

        public void write​(java.sql.ResultSet resultSet)
                   throws java.sql.SQLException,
                          java.io.IOException
        Writes a JDBC ResultSet as a CSV file. Each column in CSV file corresponds to a column in ResultSet, column order is preserved. Column names in CSV file corresponds to column names stored in ResultSetMetaData. toString will be called on each element prior to writing.
        Specified by:
        write in interface ICsvResultSetWriter
        Parameters:
        resultSet - ResultSet containing the values to write
        Throws:
        java.sql.SQLException - if a database access error occurs or this method is called on a closed result set
        java.io.IOException - if an I/O error occurred
      • write

        public void write​(java.sql.ResultSet resultSet,
                          CellProcessor[] writeProcessors)
                   throws java.sql.SQLException,
                          java.io.IOException
        Writes a JDBC ResultSet as a CSV file. Each column in CSV file corresponds to a column in ResultSet, column order is preserved. Column names in CSV file corresponds to column names stored in ResultSetMetaData. toString will be called on each (processed) element prior to writing.
        Specified by:
        write in interface ICsvResultSetWriter
        Parameters:
        resultSet - ResultSet containing the values to write
        writeProcessors - Array of CellProcessors used to further process data before it is written (each element in the processors array corresponds with a CSV column - the number of processors should match the number of columns). A null entry indicates no further processing is required (the value returned by toString() will be written as the column value).
        Throws:
        java.sql.SQLException - if a database access error occurs or this method is called on a closed result set
        java.io.IOException - if an I/O error occurred