Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
770
Xalan: The org.apache.xalan.lib.sql.XConnection Class
This
class acts as a extension function to the stylesheet. It helps to retrieve data
from database through JDBC. It is accessed by specifying a namespace URI as
follows:
xmlns:sql="http://xml.apache.org/xalan/sql"
In my examples, I have used Sun’s JDBC-ODBC
driver to connect to the database. To connect MySQL, please refer the attached
source code. This class is used when for reporting purpose. Sometimes it is
required to generate list of employees list from a database table. In such
cases, by using a stylesheet you can directly generate reports. But trick is
that you need to write your sql queries in your stylesheet. If your database
located in remote place then processing time would definitely increase.
Method Overviews
From
the stylesheet perspective, XConnection provides 3 extension functions: new(),
query(), and close(). Use new() to call one of XConnection constructors, which
establishes a JDBC driver connection to a data source and returns an
XConnection object. Then use the XConnection object query() method to return a
result set in the form of a row-set element. When you have finished working
with the row-set, call the XConnection object close() method to terminate the
connection.
Example of new()
qew() is used to call one of XConnection
constructors, which establishes a JDBC driver connection to a data source and
returns an XConnection object.
<xsl:variable
name="db" select="sql:new()"/>
Example of query()
query() is used to execute the sql statement and
returns the resultset in the form of row-set.
close() is used to close the database connection.
While using XConnection, please ensure that you have closed the database
connection using the close() method.