“DB2Xml interface” on page 368
Java support for XML schema registration and removal
The IBM Data Server Driver for JDBC and SQLJ provides methods that let you
write Java application programs to register and remove XML schemas and their
components.
The JDBC methods are:
DB2Connection.registerDB2XMLSchema
Registers an XML schema in DB2, using one or more XML schema documents.
There are two forms of this method: one form for XML schema documents that
are input from an InputStream objects, and one form for XML schema
documents that are in a String.
DB2Connection.deregisterDB2XMLObject
Removes an XML schema definition from DB2.
DB2Connection.updateDB2XmlSchema
Replaces the XML schema documents in a registered XML schema with the
XML schema documents from another registered XML schema. Optionally
drops the XML schema whose contents are copied.
Before you can invoke these methods, the underlying stored procedures must be
installed on the DB2 database server.
Example: Registration of an XML schema: The following example demonstrates the
use of registerDB2XmlSchema to register an XML schema in DB2 using a single
XML schema document (customer.xsd) that is read from an input stream. The SQL
schema name for the registered schema is SYSXSR. The xmlSchemaLocations value is
null, so DB2 will not find this XML schema on an invocation of
DSN_XMLVALIDATE that supplies a non-null XML schema location value. No
additional properties are registered.
public static void registerSchema(
Connection con,
String schemaName)
throws SQLException {
// Define the registerDB2XmlSchema parameters
String[] xmlSchemaNameQualifiers = new String[1];
String[] xmlSchemaNames = new String[1];
String[] xmlSchemaLocations = new String[1];
InputStream[] xmlSchemaDocuments = new InputStream[1];
int[] xmlSchemaDocumentsLengths = new int[1];
java.io.InputStream[] xmlSchemaDocumentsProperties = new InputStream[1];
int[] xmlSchemaDocumentsPropertiesLengths = new int[1];
InputStream xmlSchemaProperties;
int xmlSchemaPropertiesLength;
//Set the parameter values
xmlSchemaLocations[0] = "";
FileInputStream fi = null;
xmlSchemaNameQualifiers[0] = "SYSXSR";
xmlSchemaNames[0] = schemaName;
try {
fi = new FileInputStream("customer.xsd");
xmlSchemaDocuments[0] = new BufferedInputStream(fi);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Figure 22. Example of registration of an XML schema with DB2 using an XML document from an input stream
Chapter 3. JDBC application programming 71