Class CsvResultSetWriter
java.lang.Object
org.supercsv.io.AbstractCsvWriter
org.supercsv.io.CsvResultSetWriter
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, ICsvResultSetWriter, ICsvWriter
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 Summary
ConstructorsConstructorDescriptionCsvResultSetWriter(Writer writer, CsvPreference preference) Constructs a newCsvResultSetWriterwith the suppliedWriterand CSV preferences. -
Method Summary
Modifier and TypeMethodDescriptionvoidWrites a JDBCResultSetas a CSV file.voidwrite(ResultSet resultSet, CellProcessor[] writeProcessors) Writes a JDBCResultSetas a CSV file.private voidwriteContents(ResultSet resultSet) private voidwriteContents(ResultSet resultSet, CellProcessor[] writeProcessors) private voidwriteHeaders(ResultSet resultSet) Methods inherited from class AbstractCsvWriter
close, flush, getLineNumber, getRowNumber, incrementRowAndLineNo, writeComment, writeHeader, writeRow, writeRow, writeRowMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ICsvWriter
getLineNumber, getRowNumber, writeComment, writeHeader
-
Constructor Details
-
CsvResultSetWriter
Constructs a newCsvResultSetWriterwith the suppliedWriterand CSV preferences. Note that thewriterwill be wrapped in aBufferedWriterbefore accessed.- Parameters:
writer- the writerpreference- the CSV preferences- Throws:
NullPointerException- if writer or preference are null
-
-
Method Details
-
write
Writes a JDBCResultSetas a CSV file. Each column in CSV file corresponds to a column inResultSet, column order is preserved. Column names in CSV file corresponds to column names stored inResultSetMetaData.toStringwill be called on each element prior to writing.- Specified by:
writein interfaceICsvResultSetWriter- 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 setIOException- if an I/O error occurred
-
write
public void write(ResultSet resultSet, CellProcessor[] writeProcessors) throws SQLException, IOException Writes a JDBCResultSetas a CSV file. Each column in CSV file corresponds to a column inResultSet, column order is preserved. Column names in CSV file corresponds to column names stored inResultSetMetaData.toStringwill be called on each (processed) element prior to writing.- Specified by:
writein interfaceICsvResultSetWriter- Parameters:
resultSet- ResultSet containing the values to writewriteProcessors- 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). Anullentry 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 setIOException- if an I/O error occurred
-
writeHeaders
- Throws:
SQLExceptionIOException
-
writeContents
- Throws:
SQLExceptionIOException
-
writeContents
private void writeContents(ResultSet resultSet, CellProcessor[] writeProcessors) throws SQLException, IOException - Throws:
SQLExceptionIOException
-