Insert data

You can use the methods in this section to insert XML data into a database column.

The parameters in method declarations in this section have the following meanings:
  • The file parameter is an XML document. The document can be referenced by a URL (such as http://server/file.xml or file:///path/file.xml) or a path name (such as /tmp/file.xml or c:\\work\\file.xml).
  • The handler parameter is an optional class you supply, containing callback routines that the SAX parser invokes as it is parsing the file. If no value is specified, or if handler is set to NULL, the driver uses empty callback routines that echo success or failure (the driver reports failure in the form of an SQLException).
  • The validating parameter tells the SAX parser factory to use a validating parser instead of a parser that only checks form.

    If you do not specify nsa or validating, the driver uses the xml4j nonvalidating XML parser. To change the default, see Specify a parser factory.

  • The nsa parameter tells the SAX parser factory whether it can use a parser that can handle namespaces.
The following methods parse a file by using SAX and convert it to a string. You can then use the string returned by these methods as input to the PreparedStatement.setString() method to insert the data into a database column.
public String XMLtoString(String file, String handler, boolean
   validating,boolean nsa) throws SQLException

public String XMLtoString(String file, String handler) throws
   SQLException

public String XMLtoString(String file) throws SQLException
The following methods parse a file by using SAX and convert it to an object of class InputStream. You can then use the InputStream object as input to the PreparedStatement.setAsciiStream(), PreparedStatement.setBinaryStream(), or PreparedStatement.setObject() methods to insert the data into a database column.
public InputStream XMLtoInputStream(String file, String handler,
   boolean validating,boolean nsa) throws SQLException;

public InputStream XMLtoInputStream(String file, String handler)
   throws SQLException;

public InputStream XMLtoInputStream(String file) throws
   SQLException;

For examples of using these methods, see Insert data examples.

If no value is specified, or if handler is set to NULL, the driver uses the default HCL OneDB™ handler.
Important: The driver truncates any input data that is too large for a column. For example, if you insert the x.xml file into a column of type char (55) instead of a column of type char (255), the driver inserts the truncated file with no errors (the driver throws an SQLWarn exception, however). When the truncated row is selected, the parser throws a SAXParseException because the row contains invalid XML.