As described in “Exporting Data to a CSV File”, the driver can create a CSV file by exporting data from a table or ResultSet object. For example, suppose you want to export data from a 4-column table named GBMAXTABLE into a CSV file. The contents of the CSV file, named GBMAXTABLE.csv, might look like the following example:
The bulk load configuration file defines in its metadata the names and data types of the columns in the CSV file based on those in the table or ResultSet object. It also defines other data properties, such as the source code page for character data types, precision and scale for numeric data types, and nullablity for all data types. The format of GBMAXTABLE.xml might look like the following example.
<column datatype="DECIMAL" precision="38" scale="0" nullable="false">
INTEGERCOL</column>
<column datatype="VARBINARY" length="10" nullable="true">VARBINCOL</column>
<column datatype="VARCHAR" length="10" sourcecodepage="Windows-1252"
externalfilecodepage="Windows-1252" nullable="true">VCHARCOL</column>
<column datatype="VARCHAR" length="10" sourcecodepage="Windows-1252"
externalfilecodepage="Windows-1252" nullable="true">UNIVCHARCOL</column>
If the driver cannot read a bulk load configuration file (for example, because it was inadvertently deleted), the driver reads all data as character data. The character set used by the driver is UTF-8.
Before performing a bulk load operation, your application can verify the metadata in the bulk load configuration file against the structure of the target table using the validateTableFromFile() method. This ensures that the data in the CSV file is compatible with the target table structure.
Because the verification does not check the actual data in the CSV file, it is possible that the load can fail even if the verification succeeds. For example, suppose your bulk load configuration file has an Integer column that matches an Integer column in the target database. if you modified the data for the Integer column in the CSV file to contain non-digit characters, the bulk load operation would fail even though a verification using validateTableFromFile() would succeed.
Not all error messages or warnings generated by the verification process mean that the load will fail. Some messages notify you about possible incompatibilities between the source and target tables. For example, if the CSV file has a column defined as an integer and the column in the target table is defined as smallint, the load may still succeed if the values in the source column are small enough to fit in a smallint column.
When you export data from a database to a CSV file, the CSV file uses the same code page as the table from which the data was exported. If the CSV file and the target table use different code pages, performance for bulk load operations can suffer because the driver must perform a character set conversion.
For example, if the source database table uses a SHIFT-JIS code page and the target table uses a EUC-JP code page, specify
setCodePage("EUC_JP") to ensure that the CSV file will use the same code page as the target table. If the code page you need to use is not listed, contact Technical Support to request support for that code page.
When you export data into a CSV file, you can choose to create one large file or multiple smaller files. For example, if you are exporting BLOB data that is a total of several GB, you may want to break the data that into multiple smaller files of 100 MB each.
If the values set by the setCharacterThreshold() or setBinaryThreshold() methods are exceeded, separate files are generated to store character or binary data, respectively. Overflow files are located in the same directory as the CSV file.
CSV_file_name is the name of the CSV file.
xxxxxx is a 6-digit number that increments an overflow file.
If the driver was unable to load rows into the database for a bulk load operation from a CSV file, it can record all the rows that were unable to be loaded into the database in the discard file. The contents of the discard file is in the same format as that of the CSV file. After fixing reported issues in the discard file, the bulk load can be reissued, using the discard file as the CSV file.
NOTE: If coding a path on Windows to the log file in a Java string, the backslash character (\) must be preceded by the Java escape character, a backslash. For example:
C:\\temp\\discard.csv.