APIdia Launch Partner
Top Description Inners Fields Constructors Methods
net.ucanaccess.console

public final Class Exporter

extends Object
Class Inheritance
Imports
java.io.IOException, .PrintStream, java.math.BigDecimal, java.sql.ResultSet, .ResultSetMetaData, .SQLException, .Types, java.text.DecimalFormat, .DecimalFormatSymbols, .SimpleDateFormat, java.util.Arrays, .Date

Exports a ResultSet to different formats, primarily CSV.

The class uses a builder pattern to configure the export options before calling its dump methods.

For example, to export a ResultSet to a CSV file with a custom delimiter:

Exporter exporter = new Exporter.Builder()
    .setDelimiter(",")
    .build();
ResultSet rs = ...;
exporter.dumpCsv(rs, System.out);

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static final String
DEFAULT_CSV_DELIMITER

The default delimiter is semi-colon for historical reasons.

private final String
private final boolean
private final boolean
private static final String
private static final byte[]

Constructor Summary

AccessConstructor and Description
private
Exporter(String delimter, boolean includeBom, boolean preserveNewlines)

Method Summary

Modifier and TypeMethod and Description
public void
dumpCsv(ResultSet
The ResultSet to be exported.
rs
,
PrintStream
The output stream to which the CSV data will be written.
out
)

Prints the ResultSet rs in CSV format to the output stream out.

public void
dumpSchema(ResultSet
The ResultSet whose metadata will be used to generate the schema.
rs
,
PrintStream
The output stream to which the schema will be written.
out
)

Prints the Google BigQuery schema of the table given by rs in JSON format to the out stream.

pack-priv static String

Returns:

The corresponding BigQuery schema value ("required" or "nullable").
toBigQueryNullable
(int
The ResultSetMetaData.column*Nulls value.
nullable
)

Converts the nullable indicator from ResultSetMetaData.isNullable() to the equivalent BigQuery schema value.

pack-priv static String

Returns:

The corresponding BigQuery data type as a string.
toBigQueryType
(int
The java.sql.Types integer value.
sqlType
)

Maps the java.sql.Types values to BigQuery data types.

pack-priv static String

Returns:

The CSV-formatted string.
toCsv
(String
The string to be formatted as CSV.
str
,
String
The delimiter character used for the CSV output.
delimiter
,
boolean
If `true`, newline characters are kept; otherwise, they are replaced by spaces.
preserveNewlines
)

Returns the CSV representation of the given string.

pack-priv static String
toSchemaRow(String name, int sqlType, int nullable)

Returns one row of the BigQuery JSON schema file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_CSV_DELIMITERback to summary
private static final String DEFAULT_CSV_DELIMITER

The default delimiter is semi-colon for historical reasons.

delimiterback to summary
private final String delimiter
includeBomback to summary
private final boolean includeBom
preserveNewlinesback to summary
private final boolean preserveNewlines
QUOTEback to summary
private static final String QUOTE
UTF8_BYTE_ORDER_MARKback to summary
private static final byte[] UTF8_BYTE_ORDER_MARK

Constructor Detail

Exporterback to summary
private Exporter(String delimter, boolean includeBom, boolean preserveNewlines)

Method Detail

dumpCsvback to summary
public void dumpCsv(ResultSet rs, PrintStream out) throws SQLException, IOException

Prints the ResultSet rs in CSV format to the output stream out.

Parameters
rs:ResultSet

The ResultSet to be exported.

out:PrintStream

The output stream to which the CSV data will be written.

Exceptions
SQLException:
if a database access error occurs.
IOException:
if an I/O error occurs while writing to the stream.
dumpSchemaback to summary
public void dumpSchema(ResultSet rs, PrintStream out) throws SQLException

Prints the Google BigQuery schema of the table given by rs in JSON format to the out stream.
See bq command-line tool for a description of the JSON schema format.

Parameters
rs:ResultSet

The ResultSet whose metadata will be used to generate the schema.

out:PrintStream

The output stream to which the schema will be written.

Exceptions
SQLException:
if a database access error occurs.
toBigQueryNullableback to summary
pack-priv static String toBigQueryNullable(int nullable)

Converts the nullable indicator from ResultSetMetaData.isNullable() to the equivalent BigQuery schema value.

Parameters
nullable:int

The ResultSetMetaData.column*Nulls value.

Returns:String

The corresponding BigQuery schema value ("required" or "nullable").

toBigQueryTypeback to summary
pack-priv static String toBigQueryType(int sqlType)

Maps the java.sql.Types values to BigQuery data types.
We map to the BigQuery Standard SQL data types (...) instead of the legacy SQL data types (...).

Any JDBC type not explicitly defined will be mapped to a BigQuery "string" type.

Parameters
sqlType:int

The java.sql.Types integer value.

Returns:String

The corresponding BigQuery data type as a string.

toCsvback to summary
pack-priv static String toCsv(String str, String delimiter, boolean preserveNewlines)

Returns the CSV representation of the given string.
This method handles quoting and delimiter escaping according to a simplified CSV standard.

  • A double-quote character (") is escaped by replacing it with two double-quotes ("").
  • If the string contains the delimiter, it is enclosed in double-quotes.
  • Newlines (`\r`, `\n`) are either preserved (if `preserveNewlines` is `true`) or replaced with a space character. Preserved newlines will also cause the string to be enclosed in double-quotes.
Parameters
str:String

The string to be formatted as CSV.

delimiter:String

The delimiter character used for the CSV output.

preserveNewlines:boolean

If `true`, newline characters are kept; otherwise, they are replaced by spaces.

Returns:String

The CSV-formatted string.

toSchemaRowback to summary
pack-priv static String toSchemaRow(String name, int sqlType, int nullable)

Returns one row of the BigQuery JSON schema file.

net.ucanaccess.console back to summary

public Class Exporter.Builder

extends Object
Class Inheritance

Builder for Exporter.

Field Summary

Modifier and TypeField and Description
private String
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Exporter
public Exporter.Builder

Returns:

The Builder instance for method chaining.
includeBom
(boolean
If true, the BOM will be included.
value
)

Includes the Byte Order Mark (BOM) at the beginning of the output.

public Exporter.Builder

Returns:

The Builder instance for method chaining.
preserveNewlines
(boolean
If true, newlines are preserved.
preverseNewlines
)

Preserves embedded linefeed (\n) and carriage return (\r) characters in the output.

public Exporter.Builder

Returns:

The Builder instance for method chaining.
withDelimiter
(String
The delimiter character to be used.
value
)

Sets the CSV column delimiter.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delimiterback to summary
private String delimiter
includeBomback to summary
private boolean includeBom
preserveNewlinesback to summary
private boolean preserveNewlines

Constructor Detail

Builderback to summary
public Builder()

Method Detail

buildback to summary
public Exporter build()
includeBomback to summary
public Exporter.Builder includeBom(boolean value)

Includes the Byte Order Mark (BOM) at the beginning of the output.

This is often needed by applications like Excel to correctly interpret UTF-8.

Parameters
value:boolean

If true, the BOM will be included.

Returns:Exporter.Builder

The Builder instance for method chaining.

preserveNewlinesback to summary
public Exporter.Builder preserveNewlines(boolean preverseNewlines)

Preserves embedded linefeed (\n) and carriage return (\r) characters in the output.

If this is set to false, newlines will be replaced by spaces.

Parameters
preverseNewlines:boolean

If true, newlines are preserved.

Returns:Exporter.Builder

The Builder instance for method chaining.

withDelimiterback to summary
public Exporter.Builder withDelimiter(String value)

Sets the CSV column delimiter. The default is a semi-colon (";").

Parameters
value:String

The delimiter character to be used.

Returns:Exporter.Builder

The Builder instance for method chaining.