Package org.supercsv.io
Class CsvResultSetWriter
- java.lang.Object
-
- org.supercsv.io.AbstractCsvWriter
-
- org.supercsv.io.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 theResultSet
to a column in CSV file using the column names stored inResultSetMetaData
- Since:
- 2.4.0
- Author:
- SingularityFX
-
-
Constructor Summary
Constructors Constructor Description CsvResultSetWriter(java.io.Writer writer, CsvPreference preference)
Constructs a newCsvResultSetWriter
with the suppliedWriter
and CSV preferences.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
write(java.sql.ResultSet resultSet)
Writes a JDBCResultSet
as a CSV file.void
write(java.sql.ResultSet resultSet, CellProcessor[] writeProcessors)
Writes a JDBCResultSet
as a CSV file.-
Methods inherited from class org.supercsv.io.AbstractCsvWriter
close, flush, getLineNumber, getRowNumber, incrementRowAndLineNo, writeComment, writeHeader, writeRow, writeRow, writeRow
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.supercsv.io.ICsvWriter
getLineNumber, getRowNumber, writeComment, writeHeader
-
-
-
-
Constructor Detail
-
CsvResultSetWriter
public CsvResultSetWriter(java.io.Writer writer, CsvPreference preference)
Constructs a newCsvResultSetWriter
with the suppliedWriter
and CSV preferences. Note that thewriter
will be wrapped in aBufferedWriter
before accessed.- Parameters:
writer
- the writerpreference
- 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 JDBCResultSet
as 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
.toString
will be called on each element prior to writing.- Specified by:
write
in interfaceICsvResultSetWriter
- 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 setjava.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 JDBCResultSet
as 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
.toString
will be called on each (processed) element prior to writing.- Specified by:
write
in 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). Anull
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 setjava.io.IOException
- if an I/O error occurred
-
-