Class CsvResultSetWriter

java.lang.Object
org.supercsv.io.AbstractCsvWriter
org.supercsv.io.CsvResultSetWriter
All Implemented Interfaces:
Closeable, Flushable, 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
  • Constructor Details

    • CsvResultSetWriter

      public CsvResultSetWriter(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:
      NullPointerException - if writer or preference are null
  • Method Details

    • write

      public void write(ResultSet resultSet) throws SQLException, 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:
      SQLException - if a database access error occurs or this method is called on a closed result set
      IOException - if an I/O error occurred
    • write

      public void write(ResultSet resultSet, CellProcessor[] writeProcessors) throws SQLException, 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:
      SQLException - if a database access error occurs or this method is called on a closed result set
      IOException - if an I/O error occurred
    • writeHeaders

      private void writeHeaders(ResultSet resultSet) throws SQLException, IOException
      Throws:
      SQLException
      IOException
    • writeContents

      private void writeContents(ResultSet resultSet) throws SQLException, IOException
      Throws:
      SQLException
      IOException
    • writeContents

      private void writeContents(ResultSet resultSet, CellProcessor[] writeProcessors) throws SQLException, IOException
      Throws:
      SQLException
      IOException