diff --git a/jOOQ-website/src/main/resources/manual-2.5.xml b/jOOQ-website/src/main/resources/manual-2.5.xml index 546264c878..e5c102af7a 100644 --- a/jOOQ-website/src/main/resources/manual-2.5.xml +++ b/jOOQ-website/src/main/resources/manual-2.5.xml @@ -1871,7 +1871,7 @@ create.insertInto(AUTHOR, AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME) -
+
Exporting to XML, CSV, JSON, HTML, Text

Exporting with jOOQ

@@ -1881,7 +1881,7 @@ create.insertInto(AUTHOR, AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
-
+
Exporting XML

Export your results as XML

@@ -1928,7 +1928,7 @@ Document xml = create.selectFrom(BOOK).fetch().intoXML();
-
+
Exporting CSV

Export your results as CSV

@@ -1957,7 +1957,7 @@ String csv = create.selectFrom(BOOK).fetch().formatCSV(';', "{null}");
-
+
Exporting JSON

Export your results as JSON

@@ -1974,7 +1974,7 @@ String json = create.selectFrom(BOOK).fetch().formatJSON();
-
+
Exporting HTML

Export your results as HTML

@@ -2010,7 +2010,7 @@ String html = create.selectFrom(BOOK).fetch().formatHTML();
-
+
Exporting Text

Export your results as text

@@ -2038,18 +2038,126 @@ String text = create.selectFrom(BOOK).fetch().format();
- Importing - + Importing data + +

Importing data into your database using jOOQ

+

+ If you are using jOOQ for scripting purposes or in a slim, unlayered application server, you might be interested in using jOOQ's importing functionality (see also exporting functionality). You can import data directly into a table from the formats described in the subsequent sections of this manual. +

+
- CSV - + Importing CSV + +

Importing CSV with jOOQ

+ +

+ The below CSV data represents two author records that may have been exported previously, by jOOQ's , and then modified in Microsoft Excel or any other spreadsheet tool: +

+ +ID;AUTHOR_ID;TITLE +1;1;1984 +2;1;Animal Farm + +

+ With jOOQ, you can load this data using various parameters from the loader API. A simple load may look like this: +

+ +Factory create = new Factory(connection, dialect); + +// Load data into the AUTHOR table from an input stream +// holding the CSV data. +create.loadInto(AUTHOR) + .loadCSV(inputstream) + .fields(ID, AUTHOR_ID, TITLE) + .execute(); + +

+ Here are various other examples: +

+ +// Ignore the AUTHOR_ID column from the CSV file when inserting +create.loadInto(AUTHOR) + .loadCSV(inputstream) + .fields(ID, null, TITLE) + .execute(); + +// Specify behaviour for duplicate records. +create.loadInto(AUTHOR) + + // choose any of these methods + .onDuplicateKeyUpdate() + .onDuplicateKeyIgnore() + .onDuplicateKeyError() // the default + + .loadCSV(inputstream) + .fields(ID, null, TITLE) + .execute(); + +// Specify behaviour when errors occur. +create.loadInto(AUTHOR) + + // choose any of these methods + .onErrorIgnore() + .onErrorAbort() // the default + + .loadCSV(inputstream) + .fields(ID, null, TITLE) + .execute(); + +// Specify transactional behaviour where this is possible +// (e.g. not in container-managed transactions) +create.loadInto(AUTHOR) + + // choose any of these methods + .commitEach() + .commitAfter(10) + .commitAll() + .commitNone() // the default + + .loadCSV(inputstream) + .fields(ID, null, TITLE) + .execute(); + +

+ Any of the above configuration methods can be combined to achieve the type of load you need. Please refer to the API's Javadoc to learn about more details. Errors that occur during the load are reported by the execute method's result: +

+ + loader = /* .. */ .execute(); + +// The number of processed rows +int processed = loader.processed(); + +// The number of stored rows (INSERT or UPDATE) +int stored = loader.stored(); + +// The number of ignored rows (due to errors, or duplicate rule) +int ignored = loader.ignored(); + +// The errors that may have occurred during loading +List errors = loader.errors(); +LoaderError error = errors.get(0); + +// The exception that caused the error +DataAccessException exception = error.exception(); + +// The row that caused the error +int rowIndex = error.rowIndex(); +String[] row = error.row(); + +// The query that caused the error +Query query = error.query();]]> + +
XML - + +

Importing XML into jOOQ

+

This is not yet supported

+