DB2 Discovery Kit

I have posted a number of tips to use DB2. If you haven’t used DB2 before, it is one of the best databases out there, and best of all, it is available completely free from IBM. Get your DB2 discovery kit from IBM. As Grant Allen puts it in Beggining DB2, “IBM has even thought of those of you who can’t get to their website to obtain DB2. You can e-mail or telephone IBM’s DB2 team to arrange to have the Discovery Kit shipped to you.”

Register DTD for pureXML with DB2 9.7


Even though XML schema has been around for a decade, still many APIs reference a DTD in the XML documents sent back and fourth. Such is the OpenSRS API. DB2 requires an XML schema or a DTD to be registered before it will process XML documents that refer to an XML Schema or a DTD. The process of registering such XSROBJECTs with DB2 has changed in DB2 since version 8.


  • register a DTD using the DB2 9.7 command line:
    db2 REGISTER XSROBJECT 'dtd-file-name.dtd' FROM /path/to/dtd/file AS sample.dtd-name DTD

    If the command is successful, the output is
    DB20000I The REGISTER XSROBJECT command completed successfully.
  • Register a DTD from a Java program:
    String schemaName = "SAMPLE";
    String dtdName = "dtd-name";
    String dtdFile = "dtd-file-name.dtd";
    Reader fis = new FileReader(dtdFile);
    byte[] contentDtd = FileIO.readerToString(fis).getBytes();
    String registerProcQuery = "CALL SYSPROC.XSR_DTD (?,?,?,?,?)";
    PreparedStatement registerProcStatement = conn.prepareCall(registerProcQuery);
    registerProcStatement.setString(1, schemaName);
    registerProcStatement.setString(2, dtdName);
    registerProcStatement.setString(3, dtdFile);
    registerProcStatement.setString(4, "PUBLIC ID");
    registerProcStatement.setObject(5, contentDtd, java.sql.Types.BLOB);

    The FileIO class can be found in Java Cookbook, Second Edition