skip to main content
Using the driver : DataDirect Bulk Load : Using a DDBulkLoad object : Exporting data to a CSV file
  

Try DataDirect Drivers Now
Exporting data to a CSV file
Using a BulkLoad object, data can be exported either as a table or ResultSet object.

Exporting Data as a Table

To export data as a table, the application must specify the table name with the setTableName method and then export the data to a CSV file using the export method. For example, the following code snippet specifies the GBMAXTABLE table and exports it to a CSV file called tmp.csv.
bulkLoad.setTableName("GBMAXTABLE");
bulkLoad.export("tmp.csv");
Alternatively, you can create a file reference to the CSV file and use the export method to specify the file reference. For example:
File csvFile = new File ("tmp.csv");
bulkLoad.export(csvFile);

Exporting Data as a ResultSet object

To export data as a ResultSet object, the application must first create a file reference to a CSV file, and then, using the export method, specify the ResultSet object and the file reference. For example, the following code snippet creates the tmp.csv file reference and then specifies MyResults (the ResultSet object be exported).
File csvFile = new File ("tmp.csv");
bulkLoad.export(MyResults, csvFile);
If the CSV file does not already exist, the driver creates it when the export method is executed. The driver also creates a bulk load configuration file, which describes the structure of the CSV file. For more information about using CSV files, see "CSV Files." See "JDBC Extensions" for more information about bulk load methods.