Loading Data From a CSV File
- Last Updated: May 18, 2020
- 1 minute read
- DataDirect Connectors
- JDBC
- IBM Db2 5.1
- MySQL 5.1
- Progress OpenEdge 5.1
- SAP Sybase 5.1
- Documentation
Use the setTableName() method to specify the table to load the data. Then, use the load() method, specifying the CSV file. For example, to load data from a file named tmp.csv into a table named GBMAXTABLE, you would specify:
bulkLoad.setTableName("GBMAXTABLE");
and
bulkLoad.load("tmp.csv");
Alternatively, you can create a file reference to the CSV file, and use the load() method to specify the file reference:
File csvFile = new File("tmp.csv");
bulkLoad.load(csvFile);
For the Salesforce driver, you also can specify the columns to which you want to load the data. This example loads the first column in the CSV file to the ColName1 column, the second column in the CSV file to the ColName2 column, and the third column in the CSV file to the ColName3 column:
bulkLoad.setTableName("GBMAXTABLE(ColName1, ColName2, ColName3)");
and
bulkLoad.load("tmp.csv");
Use the BulkLoadBatchSize property to specify the number of rows the driver loads at a time when bulk loading data. Performance can be improved by increasing the number of rows the driver loads at a time because fewer network round trips are required. Be aware that increasing the number of rows that are loaded also causes the driver to consume more memory on the client.
Refer to JDBC extensions in the Progress DataDirect for JDBC Drivers Reference for more information about bulk load methods.