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);
| Modifier and Type | Class and Description |
|---|---|
| public static class | Exporter.
Builder for |
| Modifier and Type | Field 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[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method 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 |
| 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 |
| pack-priv static String | Returns: The corresponding BigQuery schema value ("required" or "nullable").The nullable)ResultSetMetaData.column*Nulls value.Converts the |
| pack-priv static String | Returns: The corresponding BigQuery data type as a string.The sqlType)java.sql.Types integer value.Maps the |
| pack-priv static String | Returns: The CSV-formatted 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. |
| DEFAULT_CSV_DELIMITER | back to summary |
|---|---|
| private static final String DEFAULT_CSV_DELIMITER The default delimiter is semi-colon for historical reasons. | |
| delimiter | back to summary |
|---|---|
| private final String delimiter | |
| includeBom | back to summary |
|---|---|
| private final boolean includeBom | |
| preserveNewlines | back to summary |
|---|---|
| private final boolean preserveNewlines | |
| QUOTE | back to summary |
|---|---|
| private static final String QUOTE | |
| UTF8_BYTE_ORDER_MARK | back to summary |
|---|---|
| private static final byte[] UTF8_BYTE_ORDER_MARK | |
| Exporter | back to summary |
|---|---|
| private Exporter(String delimter, boolean includeBom, boolean preserveNewlines) | |
| dumpCsv | back to summary |
|---|---|
| public void dumpCsv(ResultSet rs, PrintStream out) throws SQLException, IOException Prints the ResultSet
| |
| dumpSchema | back to summary |
|---|---|
| public void dumpSchema(ResultSet rs, PrintStream out) throws SQLException Prints the Google BigQuery schema of the table given by
| |
| toBigQueryNullable | back to summary |
|---|---|
| pack-priv static String toBigQueryNullable(int nullable) Converts the
| |
| toBigQueryType | back to summary |
|---|---|
| pack-priv static String toBigQueryType(int sqlType) Maps the Any JDBC type not explicitly defined will be mapped to a BigQuery "string" type.
| |
| toCsv | back to summary |
|---|---|
| pack-priv static String toCsv(String str, String delimiter, boolean preserveNewlines) Returns the CSV representation of the given string.
| |
| toSchemaRow | back to summary |
|---|---|
| pack-priv static String toSchemaRow(String name, int sqlType, int nullable) Returns one row of the BigQuery JSON schema file. | |
Exporter.
| Modifier and Type | Field and Description |
|---|---|
| private String | |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Exporter | |
| public Exporter. | Returns: The Builder instance for method chaining.If value)true, the BOM will be included.Includes the Byte Order Mark (BOM) at the beginning of the output. |
| public Exporter. | Returns: The Builder instance for method chaining.If preverseNewlines)true, newlines are preserved.Preserves embedded linefeed ( |
| public Exporter. | Returns: The Builder instance for method chaining.The delimiter character to be used. value)Sets the CSV column delimiter. |
| delimiter | back to summary |
|---|---|
| private String delimiter | |
| includeBom | back to summary |
|---|---|
| private boolean includeBom | |
| preserveNewlines | back to summary |
|---|---|
| private boolean preserveNewlines | |
| Builder | back to summary |
|---|---|
| public Builder() | |
| build | back to summary |
|---|---|
| public Exporter build() | |
| includeBom | back to summary |
|---|---|
| public Exporter. 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. | |
| preserveNewlines | back to summary |
|---|---|
| public Exporter. Preserves embedded linefeed (
If this is set to | |
| withDelimiter | back to summary |
|---|---|
| public Exporter. Sets the CSV column delimiter. The default is a semi-colon (";"). | |