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
Reading string arrays
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
DSLContext.fetchFromStringData() is the method that all of the previous text based methods are built upon. It is useful when data has already been split into rows and columns, e.g. by a third party CSV parser or spreadsheet library:
// By default, the first array contains the field names
Result<Record> result = create.fetchFromStringData(
new String[] { "ID", "AUTHOR_ID", "TITLE" },
new String[] { "1", "1", "1984" },
new String[] { "2", "1", "Animal Farm" }
);
// Data without header row. Field names COL1, COL2, ..., COLn are generated
List<String[]> data = ...;
Result<Record> result = create.fetchFromStringData(data, false);
The number of columns is defined by the first array. Excess data in subsequent arrays is ignored, and missing data is filled with NULL. All fields of the resulting Result are of type String.
Arrays of arbitrary objects, rather than strings, can also be imported directly into a table using the Loader API.
Feedback
Do you have any feedback about this page? We'd love to hear it!