DB2 application programming language support for XML

You can write applications to store XML data in DB2® database tables or retrieve XML data from tables. XML parameters for external stored procedures or user-defined functions are not supported.

You can use any of the following languages to write your applications:
  • C or C++ (in embedded SQL or DB2 ODBC applications)
  • COBOL
  • Java (JDBC or SQLJ)
  • Assembler
  • PL/I

Start of changeAn application program can retrieve an entire document or a fragment of a document from an XML column, or store an entire document or a fragment of a document in an XML column.End of change

When an application provides an XML value to a DB2 database server, the database server converts the data from the textual XML format to the XML hierarchical format, in Unicode UTF-8 encoding.

Start of changeWhen an application retrieves data from XML columns, the DB2 database server converts the data from the XML hierarchical format to one of the following formats:
  • The textual XML format. For the textual XML format, the database server might need to convert the output data from UTF-8 to the application encoding.
  • The XML binary format. This format is an option only for JDBC, SQLJ, or ODBC applications.
End of change

When you retrieve XML data, you need to be aware of the effect of code page conversion on data loss. Data loss can occur when characters in the source code page cannot be represented in the target code page.

An application can retrieve an entire XML document or a sequence from an XML column.

When you fetch an entire XML document, you retrieve the document into an application variable.

To retrieve an XML sequence, within an SQL FETCH or single-row SELECT INTO operation, you call the XMLQUERY built-in function, passing an XQuery expression as an argument. XMLQUERY is a scalar function that returns the entire sequence in an application variable.