Top Description Fields Constructors Methods
com.opencsv

public Class ResultSetColumnNameHelperService

extends ResultSetHelperService
implements ResultSetHelper
Class Inheritance
All Implemented Interfaces
com.opencsv.ResultSetHelper
Imports
org.apache.commons.lang3.ArrayUtils, .ObjectUtils, .StringUtils, java.io.IOException, java.sql.ResultSet, .SQLException, java.util.*, java.util.stream.Collectors, .Stream

Helper class for processing JDBC ResultSet objects allowing the user to process a subset of columns and set custom header names.

Field Summary

Modifier and TypeField and Description
private String[]
private final Map<String, Integer>
private String[]
private Locale
Inherited from com.opencsv.ResultSetHelperService:
CLOBBUFFERSIZEdateFormatdateTimeFormatDEFAULT_DATE_FORMATDEFAULT_TIMESTAMP_FORMATfloatingPointFormatintegerFormatnullDefault

Constructor Summary

AccessConstructor and Description
public
ResultSetColumnNameHelperService()

Nullary constructor.

Method Summary

Modifier and TypeMethod and Description
public String[]

Returns:

A string array containing the column names.
getColumnNames
(ResultSet
ResultSet
rs
)

Overrides com.opencsv.ResultSetHelperService.getColumnNames.

Implements com.opencsv.ResultSetHelper.getColumnNames.

Returns the column names from the result set.

public String[]

Returns:

String array containing all the column values.
getColumnValues
(ResultSet
The ResultSet containing the values.
rs
)

Overrides com.opencsv.ResultSetHelperService.getColumnValues.

Implements com.opencsv.ResultSetHelper.getColumnValues.

Get all the column values from the result set.

public String[]

Returns:

String array containing all the column values.
getColumnValues
(ResultSet
The ResultSet containing the values.
rs
,
boolean
Values should have white spaces trimmed.
trim
)

Overrides com.opencsv.ResultSetHelperService.getColumnValues.

Implements com.opencsv.ResultSetHelper.getColumnValues.

Get all the column values from the result set.

public String[]

Returns:

String array containing all the column values.
getColumnValues
(ResultSet
The ResultSet containing the values.
rs
,
boolean
Values should have white spaces trimmed.
trim
,
String
Format string for dates.
dateFormatString
,
String
Format string for timestamps.
timeFormatString
)

Overrides com.opencsv.ResultSetHelperService.getColumnValues.

Implements com.opencsv.ResultSetHelper.getColumnValues.

Get all the column values from the result set.

private String[]
getColumnValueSubset(String[] realColumnValues)

private boolean
private void
public void
setColumnNames(String[]
The JDBC column names to export, in the desired order
columnNames
,
String[]
The column headers of the CSV file, in the desired order
columnHeaders
)

Set the JDBC column names to use, and the header text for the CSV file

public void
setErrorLocale(Locale
Locale for error messages. If null, the default locale is used.
errorLocale
)

Sets the locale for error messages.

Inherited from com.opencsv.ResultSetHelperService:
handleClobhandleDatehandleNClobhandleNVarCharhandleTimestamphandleVarCharsetDateFormatsetDateTimeFormatsetFloatingPointFormatsetIntegerFormatsetNullDefault

Field Detail

columnHeadersback to summary
private String[] columnHeaders
columnNamePositionMapback to summary
private final Map<String, Integer> columnNamePositionMap
columnNamesback to summary
private String[] columnNames
errorLocaleback to summary
private Locale errorLocale

Constructor Detail

ResultSetColumnNameHelperServiceback to summary
public ResultSetColumnNameHelperService()

Nullary constructor.

Method Detail

getColumnNamesback to summary
public String[] getColumnNames(ResultSet rs) throws SQLException

Overrides com.opencsv.ResultSetHelperService.getColumnNames.

Implements com.opencsv.ResultSetHelper.getColumnNames.

Returns the column names from the result set.

Parameters
rs:ResultSet

ResultSet

Returns:String[]

A string array containing the column names.

Annotations
@Override
Exceptions
SQLException:
Thrown by the result set.
getColumnValuesback to summary
public String[] getColumnValues(ResultSet rs) throws SQLException, IOException

Overrides com.opencsv.ResultSetHelperService.getColumnValues.

Implements com.opencsv.ResultSetHelper.getColumnValues.

Get all the column values from the result set.

Parameters
rs:ResultSet

The ResultSet containing the values.

Returns:String[]

String array containing all the column values.

Annotations
@Override
Exceptions
SQLException:
Thrown by the result set.
IOException:
Thrown by the result set.
getColumnValuesback to summary
public String[] getColumnValues(ResultSet rs, boolean trim) throws SQLException, IOException

Overrides com.opencsv.ResultSetHelperService.getColumnValues.

Implements com.opencsv.ResultSetHelper.getColumnValues.

Get all the column values from the result set.

Parameters
rs:ResultSet

The ResultSet containing the values.

trim:boolean

Values should have white spaces trimmed.

Returns:String[]

String array containing all the column values.

Annotations
@Override
Exceptions
SQLException:
Thrown by the result set.
IOException:
Thrown by the result set.
getColumnValuesback to summary
public String[] getColumnValues(ResultSet rs, boolean trim, String dateFormatString, String timeFormatString) throws SQLException, IOException

Overrides com.opencsv.ResultSetHelperService.getColumnValues.

Implements com.opencsv.ResultSetHelper.getColumnValues.

Get all the column values from the result set.

Parameters
rs:ResultSet

The ResultSet containing the values.

trim:boolean

Values should have white spaces trimmed.

dateFormatString:String

Format string for dates.

timeFormatString:String

Format string for timestamps.

Returns:String[]

String array containing all the column values.

Annotations
@Override
Exceptions
SQLException:
Thrown by the result set.
IOException:
Thrown by the result set.
getColumnValueSubsetback to summary
private String[] getColumnValueSubset(String[] realColumnValues)
hasInvalidValueback to summary
private boolean hasInvalidValue(String[] strings)
populateColumnDataback to summary
private void populateColumnData(ResultSet rs) throws SQLException
setColumnNamesback to summary
public void setColumnNames(String[] columnNames, String[] columnHeaders)

Set the JDBC column names to use, and the header text for the CSV file

Parameters
columnNames:String[]

The JDBC column names to export, in the desired order

columnHeaders:String[]

The column headers of the CSV file, in the desired order

Exceptions
UnsupportedOperationException:
If the number of headers is different than the number of columns, or if any of the columns or headers is blank or null.
setErrorLocaleback to summary
public void setErrorLocale(Locale errorLocale)

Sets the locale for error messages.

Parameters
errorLocale:Locale

Locale for error messages. If null, the default locale is used.

Since
4.0