Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12
This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.
Reading CSV
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
DSLContext.fetchFromCSV() is the inverse operation of exporting CSV. It parses a CSV string into a Result<Record>:
Result<Record> result = create.fetchFromCSV(
"ID,AUTHOR_ID,TITLE\n"
+ "1,1,1984\n"
+ "2,1,Animal Farm\n"
);
By default, the first line is interpreted as a header line, defining the field names, and values are expected to be separated by a comma. Both defaults can be overridden:
// Use ";" as the delimiter Result<Record> result = create.fetchFromCSV(csv, ';'); // The CSV content has no header line. Field names COL1, COL2, ..., COLn are generated Result<Record> result = create.fetchFromCSV(csv, false); // Both of the above Result<Record> result = create.fetchFromCSV(csv, false, ';');
CSV has no notion of data types, so all fields of the resulting Result are of type String. Missing values produce NULL, empty values produce empty strings. See the section about working with in-memory results to learn how to convert such results to other types.
If the goal is to load CSV data directly into a database table, the Loader API's CSV support may be a better fit.
Feedback
Do you have any feedback about this page? We'd love to hear it!