Class JDBC4MysqlSQLXML

java.lang.Object
com.mysql.jdbc.JDBC4MysqlSQLXML
All Implemented Interfaces:
SQLXML

public class JDBC4MysqlSQLXML extends Object implements SQLXML
  • Constructor Details

  • Method Details

    • free

      public void free() throws SQLException
      Specified by:
      free in interface SQLXML
      Throws:
      SQLException
    • getString

      public String getString() throws SQLException
      Specified by:
      getString in interface SQLXML
      Throws:
      SQLException
    • setString

      public void setString(String str) throws SQLException
      Sets the XML value designated by this SQLXML instance to the given String representation. The format of this String is defined by org.xml.sax.InputSource, where the characters in the stream represent the unicode code points for XML according to section 2 and appendix B of the XML 1.0 specification. Although an encoding declaration other than unicode may be present, the encoding of the String is unicode. The behavior of this method is the same as ResultSet.updateString() when the designated column of the ResultSet has a type java.sql.Types of SQLXML.

      The SQL XML object becomes not writeable when this method is called and may also become not readable depending on implementation.

      Specified by:
      setString in interface SQLXML
      Parameters:
      value - the XML value
      Throws:
      SQLException - if there is an error processing the XML value. The getCause() method of the exception may provide a more detailed exception, for example, if the stream does not contain valid characters. An exception is thrown if the state is not writable.
      SQLFeatureNotSupportedException - if the JDBC driver does not support this method
      Since:
      1.6
    • isEmpty

      public boolean isEmpty() throws SQLException
      Throws:
      SQLException
    • getBinaryStream

      public InputStream getBinaryStream() throws SQLException
      Specified by:
      getBinaryStream in interface SQLXML
      Throws:
      SQLException
    • getCharacterStream

      public Reader getCharacterStream() throws SQLException
      Retrieves the XML value designated by this SQLXML instance as a java.io.Reader object. The format of this stream is defined by org.xml.sax.InputSource, where the characters in the stream represent the unicode code points for XML according to section 2 and appendix B of the XML 1.0 specification. Although an encoding declaration other than unicode may be present, the encoding of the stream is unicode. The behavior of this method is the same as ResultSet.getCharacterStream() when the designated column of the ResultSet has a type java.sql.Types of SQLXML.

      The SQL XML object becomes not readable when this method is called and may also become not writable depending on implementation.

      Specified by:
      getCharacterStream in interface SQLXML
      Returns:
      a stream containing the XML data.
      Throws:
      SQLException - if there is an error processing the XML value. The getCause() method of the exception may provide a more detailed exception, for example, if the stream does not contain valid characters. An exception is thrown if the state is not readable.
      SQLFeatureNotSupportedException - if the JDBC driver does not support this method
      Since:
      1.6
    • getSource

      public <T extends Source> T getSource(Class<T> clazz) throws SQLException
      Returns a Source for reading the XML value designated by this SQLXML instance. Sources are used as inputs to XML parsers and XSLT transformers.

      Sources for XML parsers will have namespace processing on by default. The systemID of the Source is implementation dependent.

      The SQL XML object becomes not readable when this method is called and may also become not writable depending on implementation.

      Note that SAX is a callback architecture, so a returned SAXSource should then be set with a content handler that will receive the SAX events from parsing. The content handler will receive callbacks based on the contents of the XML.

      SAXSource saxSource = sqlxml.getSource(SAXSource.class);
      XMLReader xmlReader = saxSource.getXMLReader();
      xmlReader.setContentHandler(myHandler);
      xmlReader.parse(saxSource.getInputSource());
      
      Specified by:
      getSource in interface SQLXML
      Parameters:
      sourceClass - The class of the source, or null. If the class is null, a vendor specifc Source implementation will be returned. The following classes are supported at a minimum: (MySQL returns a SAXSource if sourceClass == null)
         javax.xml.transform.dom.DOMSource - returns a DOMSource
         javax.xml.transform.sax.SAXSource - returns a SAXSource
         javax.xml.transform.stax.StAXSource - returns a StAXSource
         javax.xml.transform.stream.StreamSource - returns a StreamSource
                 
      Returns:
      a Source for reading the XML value.
      Throws:
      SQLException - if there is an error processing the XML value or if this feature is not supported. The getCause() method of the exception may provide a more detailed exception, for example, if an XML parser exception occurs. An exception is thrown if the state is not readable.
      SQLFeatureNotSupportedException - if the JDBC driver does not support this method
      Since:
      1.6
    • setBinaryStream

      public OutputStream setBinaryStream() throws SQLException
      Retrieves a stream that can be used to write the XML value that this SQLXML instance represents. The stream begins at position 0. The bytes of the stream are interpreted according to appendix F of the XML 1.0 specification The behavior of this method is the same as ResultSet.updateBinaryStream() when the designated column of the ResultSet has a type java.sql.Types of SQLXML.

      The SQL XML object becomes not writeable when this method is called and may also become not readable depending on implementation.

      Specified by:
      setBinaryStream in interface SQLXML
      Returns:
      a stream to which data can be written.
      Throws:
      SQLException - if there is an error processing the XML value. An exception is thrown if the state is not writable.
      SQLFeatureNotSupportedException - if the JDBC driver does not support this method
      Since:
      1.6
    • setCharacterStream

      public Writer setCharacterStream() throws SQLException
      Retrieves a stream to be used to write the XML value that this SQLXML instance represents. The format of this stream is defined by org.xml.sax.InputSource, where the characters in the stream represent the unicode code points for XML according to section 2 and appendix B of the XML 1.0 specification. Although an encoding declaration other than unicode may be present, the encoding of the stream is unicode. The behavior of this method is the same as ResultSet.updateCharacterStream() when the designated column of the ResultSet has a type java.sql.Types of SQLXML.

      The SQL XML object becomes not writeable when this method is called and may also become not readable depending on implementation.

      Specified by:
      setCharacterStream in interface SQLXML
      Returns:
      a stream to which data can be written.
      Throws:
      SQLException - if there is an error processing the XML value. The getCause() method of the exception may provide a more detailed exception, for example, if the stream does not contain valid characters. An exception is thrown if the state is not writable.
      SQLFeatureNotSupportedException - if the JDBC driver does not support this method
      Since:
      1.6
    • setResult

      public <T extends Result> T setResult(Class<T> clazz) throws SQLException
      Returns a Result for setting the XML value designated by this SQLXML instance.

      The systemID of the Result is implementation dependent.

      The SQL XML object becomes not writeable when this method is called and may also become not readable depending on implementation.

      Note that SAX is a callback architecture and the returned SAXResult has a content handler assigned that will receive the SAX events based on the contents of the XML. Call the content handler with the contents of the XML document to assign the values.

      SAXResult saxResult = sqlxml.setResult(SAXResult.class);
      ContentHandler contentHandler = saxResult.getXMLReader().getContentHandler();
      contentHandler.startDocument();
      // set the XML elements and attributes into the result
      contentHandler.endDocument();
      
      Specified by:
      setResult in interface SQLXML
      Parameters:
      resultClass - The class of the result, or null. If resultClass is null, a vendor specific Result implementation will be returned. The following classes are supported at a minimum:
         javax.xml.transform.dom.DOMResult - returns a DOMResult
         javax.xml.transform.sax.SAXResult - returns a SAXResult
         javax.xml.transform.stax.StAXResult - returns a StAXResult
         javax.xml.transform.stream.StreamResult - returns a StreamResult
                 
      Returns:
      Returns a Result for setting the XML value.
      Throws:
      SQLException - if there is an error processing the XML value or if this feature is not supported. The getCause() method of the exception may provide a more detailed exception, for example, if an XML parser exception occurs. An exception is thrown if the state is not writable.
      SQLFeatureNotSupportedException - if the JDBC driver does not support this method
      Since:
      1.6
    • readerToString

      protected String readerToString(Reader reader) throws SQLException
      Throws:
      SQLException
    • serializeAsCharacterStream

      protected Reader serializeAsCharacterStream() throws SQLException
      Throws:
      SQLException
    • domSourceToString

      protected String domSourceToString() throws SQLException
      Throws:
      SQLException
    • serializeAsString

      protected String serializeAsString() throws SQLException
      Throws:
      SQLException