Package org.apache.xalan.lib.sql

**Experimental** Provides extension functions for connecting to a JDBC data source, executing a query, and working incrementally through "streamable" result set.

See:
          Description

Interface Summary
ConnectionPool An interface used to build wrapper classes around existing Connection Pool libraries.
 

Class Summary
Column **Experimental** Represents a col node from a row node.
ColumnAttribute **Experimental** Represents a column attribute on a column-header element.
ColumnData **Experimental** Represents the col element text node, i.e., the column value.
ColumnHeader **Experimental** This class represents a column-header Node, which contains the metadata for a column.
DefaultConnectionPool  
ExtensionError A base class that will convert an exception into an XML stream that can be returned in place of the standard result.
PooledConnection  
QueryParameter Title:
Row **Experimental** This class represents a row from a query result set.
RowSet **Experimental** This class represents the row-set StreamableNode, a "streamable" holder for the JDBC query result set.
SQLExtensionError Title:
StreamableNode **Experimental** This is the superclass for all nodes in the org.apache.xalan.lib.sql package.
XConnection An XSLT extension that allows a stylesheet to access JDBC data.
XConnectionPoolManager  
XStatement Represents a JDBC query statement.
 

Package org.apache.xalan.lib.sql Description

**Experimental** Provides extension functions for connecting to a JDBC data source, executing a query, and working incrementally through "streamable" result set.

The SQL extension use of a single row-set node to incrementally return a query result set is experimental. Keep in mind that you can only access row elements one at a time moving forward through the result set. The use of XPath expressions in your stylesheet, for example, that attempt to return nodes from the result set in any other manner may produce unpredictable results.

XConnection provides three extension functions that you can use in your stylesheet.

  1. new() -- Use one of the XConnection constructors to connect to a data source, and return an XConnection object.

  2. query() -- Use the XConnection object query() method to return a "streamable" result set in the form of a row-set node. Work your way through the row-set one row at a time. The same row element is used over and over again, so you can begin "transforming" the row-set before the entire result set has been returned.

  3. close() -- Use the XConnection object close() method to terminate the connection.

The query() extension function returns a Document node that contains (as needed) an array of column-header elements, a single row element that is used repeatedly, and an array of col elements. Each column-header element (one per column in the row-set) contains an attribute (ColumnAttribute) for each of the column descriptors in the ResultSetMetaData object. Each col element contains a text node with a textual representation of the value for that column in the current row.

Example

This example displays the result set from a table in a sample InstantDB database.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                xmlns:sql="org.apache.xalan.lib.sql.XConnection"
                extension-element-prefixes="sql">
  <xsl:output method="html" indent="yes"/>
  <xsl:param name="query" select="'SELECT * FROM import1'"/>
 
  <xsl:template match="/">
    <!-- 1. Make the connection -->
    <xsl:variable name="products"
                  select="sql:new('org.enhydra.instantdb.jdbc.idbDriver',
                                'jdbc:idb:D:\instantdb\Examples\sample.prp')"/>
    <HTML>
      <HEAD>
      </HEAD>
      <BODY>
        <TABLE border="1">
        <!--2. Execute the query -->
        <xsl:variable name="table" select='sql:query($products, $query)'/>
          <TR>
          <!-- Get column-label attribute from each column-header-->
          <xsl:for-each select="$table/row-set/column-header">
            <TH><xsl:value-of select="@column-label"/></TH>
          </xsl:for-each>
          </TR>
          <xsl:apply-templates select="$table/row-set/row"/>
          <xsl:text>&#10;</xsl:text>
        </TABLE>
      </BODY>
    </HTML> 
    <!-- 3. Close the connection -->
    <xsl:value-of select="sql:close($products)"/>
  </xsl:template>

  <xsl:template match="row">
        <TR>
          <xsl:apply-templates select="col"/>
        </TR>
  </xsl:template>

  <xsl:template match="col">
    <TD>
      <!-- Here is the column data -->
      <xsl:value-of select="text()"/>
    </TD>
  </xsl:template>

</xsl:stylesheet>



Copyright © 2000 Apache XML Project. All Rights Reserved.