Package com.opencsv
Class ResultSetColumnNameHelperService
- java.lang.Object
-
- com.opencsv.ResultSetHelperService
-
- com.opencsv.ResultSetColumnNameHelperService
-
- All Implemented Interfaces:
ResultSetHelper
public class ResultSetColumnNameHelperService extends ResultSetHelperService implements ResultSetHelper
Helper class for processing JDBC ResultSet objects allowing the user to process a subset of columns and set custom header names.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String[]columnHeadersprivate java.util.Map<java.lang.String,java.lang.Integer>columnNamePositionMapprivate java.lang.String[]columnNamesprivate java.util.LocaleerrorLocale-
Fields inherited from class com.opencsv.ResultSetHelperService
CLOBBUFFERSIZE, dateFormat, dateTimeFormat, DEFAULT_DATE_FORMAT, DEFAULT_TIMESTAMP_FORMAT, floatingPointFormat, integerFormat
-
-
Constructor Summary
Constructors Constructor Description ResultSetColumnNameHelperService()Nullary constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]getColumnNames(java.sql.ResultSet rs)Returns the column names from the result set.java.lang.String[]getColumnValues(java.sql.ResultSet rs)Get all the column values from the result set.java.lang.String[]getColumnValues(java.sql.ResultSet rs, boolean trim)Get all the column values from the result set.java.lang.String[]getColumnValues(java.sql.ResultSet rs, boolean trim, java.lang.String dateFormatString, java.lang.String timeFormatString)Get all the column values from the result set.private java.lang.String[]getColumnValueSubset(java.lang.String[] realColumnValues)private booleanhasInvalidValue(java.lang.String[] strings)private voidpopulateColumnData(java.sql.ResultSet rs)voidsetColumnNames(java.lang.String[] columnNames, java.lang.String[] columnHeaders)Set the JDBC column names to use, and the header text for the CSV filevoidsetErrorLocale(java.util.Locale errorLocale)Sets the locale for error messages.-
Methods inherited from class com.opencsv.ResultSetHelperService
handleClob, handleDate, handleNClob, handleNVarChar, handleTimestamp, handleVarChar, setDateFormat, setDateTimeFormat, setFloatingPointFormat, setIntegerFormat
-
-
-
-
Method Detail
-
setErrorLocale
public void setErrorLocale(java.util.Locale errorLocale)
Sets the locale for error messages.- Parameters:
errorLocale- Locale for error messages. If null, the default locale is used.- Since:
- 4.0
-
setColumnNames
public void setColumnNames(java.lang.String[] columnNames, java.lang.String[] columnHeaders)Set the JDBC column names to use, and the header text for the CSV file- Parameters:
columnNames- The JDBC column names to export, in the desired ordercolumnHeaders- The column headers of the CSV file, in the desired order- Throws:
java.lang.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.
-
hasInvalidValue
private boolean hasInvalidValue(java.lang.String[] strings)
-
getColumnNames
public java.lang.String[] getColumnNames(java.sql.ResultSet rs) throws java.sql.SQLExceptionReturns the column names from the result set.- Specified by:
getColumnNamesin interfaceResultSetHelper- Overrides:
getColumnNamesin classResultSetHelperService- Parameters:
rs- ResultSet- Returns:
- A string array containing the column names.
- Throws:
java.sql.SQLException- Thrown by the result set.
-
populateColumnData
private void populateColumnData(java.sql.ResultSet rs) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getColumnValues
public java.lang.String[] getColumnValues(java.sql.ResultSet rs) throws java.sql.SQLException, java.io.IOExceptionGet all the column values from the result set.- Specified by:
getColumnValuesin interfaceResultSetHelper- Overrides:
getColumnValuesin classResultSetHelperService- Parameters:
rs- The ResultSet containing the values.- Returns:
- String array containing all the column values.
- Throws:
java.sql.SQLException- Thrown by the result set.java.io.IOException- Thrown by the result set.
-
getColumnValues
public java.lang.String[] getColumnValues(java.sql.ResultSet rs, boolean trim) throws java.sql.SQLException, java.io.IOExceptionGet all the column values from the result set.- Specified by:
getColumnValuesin interfaceResultSetHelper- Overrides:
getColumnValuesin classResultSetHelperService- Parameters:
rs- The ResultSet containing the values.trim- Values should have white spaces trimmed.- Returns:
- String array containing all the column values.
- Throws:
java.sql.SQLException- Thrown by the result set.java.io.IOException- Thrown by the result set.
-
getColumnValues
public java.lang.String[] getColumnValues(java.sql.ResultSet rs, boolean trim, java.lang.String dateFormatString, java.lang.String timeFormatString) throws java.sql.SQLException, java.io.IOExceptionGet all the column values from the result set.- Specified by:
getColumnValuesin interfaceResultSetHelper- Overrides:
getColumnValuesin classResultSetHelperService- Parameters:
rs- The ResultSet containing the values.trim- Values should have white spaces trimmed.dateFormatString- Format string for dates.timeFormatString- Format string for timestamps.- Returns:
- String array containing all the column values.
- Throws:
java.sql.SQLException- Thrown by the result set.java.io.IOException- Thrown by the result set.
-
getColumnValueSubset
private java.lang.String[] getColumnValueSubset(java.lang.String[] realColumnValues)
-
-