You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Eric Everman <ev...@precedadesign.com> on 2005/03/24 20:35:55 UTC

JNDI Connection Library Avail. for SQL Extension

Hi-

I've put together a version of the SQL extension that accepts JNDI 
named connections.  The usage is (nearly) identical to the current SQL 
extension except that a JNDI name is accepted in place of a 
ConnectionPool.  The key class is JNDIXConnection, which is used in 
place of XConnection.  The xalan_jndi_datasource.jar can simply be 
added to the classpath - it does not replace the Xalan library, but is 
added to it.  Here is an example XSLT sheet using the class:


===================== XML ========================================
<?xml version="1.0"?>
<xsl:stylesheet
			version="1.0"
			xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:sql="xalan://org.apache.xalan.lib.sql.JNDIXConnection"
			extension-element-prefixes="sql">

	<xsl:variable name="jndiDatasource">jndi/mydatasource</xsl:param>

	
	<xsl:template match="/">

		<xsl:param name="queryString">SELECT COUNT(*) FROM mytable</xsl:param>

     <xsl:variable name="dbConnection" select="sql:new()"/>
		<xsl:if test="not(sql:connect($dbConnection, $jndiDatasource))">
			<h1>Series Listing failed to connect to db via jndi connection</h1
		</xsl:if>

		<xsl:variable name="table" select='sql:query($dbConnection, 
$queryString)'/>

		<xsl:if test="not($table)">
			<h1>Error in Query</h1>
			<xsl:copy-of select="sql:getError($dbConnection)/ext-error"/>
		</xsl:if>

		<xsl:apply-templates select="$table/sql/row-set"/>

     <!-- Closes this individual connection, returning nothing -->
     <xsl:value-of select="sql:close($dbConnection)"/>
	</xsl:template>


	<xsl:template match="row">
		<h1><xsl:value-of select="col[position() = 1]"/></h1>
	</xsl:template>

</xsl:stylesheet>
===================== /XML ========================================

Comments are appreciated.  I'm not sure if the attachments will come 
thru, you are welcome to email me at:
eeverman at precedadesign d-o-t com if you would like a copy and did 
not receive it with this email.

Thanks,
Eric Everman