SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
| Introduction
» | sql:connect
| sql:query
| sql:insert and sql:column
| sql:update and sql:column
| sql:delete
| sql:close
| Example
| A Warning about Side-Effects
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# sql:connect

`sql:connect` creates a database connection. It has attributes `driver`, `database`, `user`, and `password`, all of which are attribute value templates (so the values can be passed in as parameters). The `driver` attribute names the JDBC driver class to be used. The database name must be a name that JDBC can associate with an actual database.

The `sql:connect` instruction returns a database connection as a value, specifically a value of type "external object", which can be referred to using the type `java:java.sql.Connection`. Typically the value will be assigned to a variable using the construct:

    <xsl:variable name="connection"
                  as="java:java.sql.Connection"
                  xmlns:java="http://saxon.sf.net/java-type">
      <sql:connect database="jdbc:odbc:testdb"
                  driver="sun.jdbc.odbc.JdbcOdbcDriver"
                  xsl:extension-element-prefixes="sql"/>
    </xsl:variable>

This can be a global variable or a local variable; if local, it can be passed to other templates as a parameter in the normal way. The connection is used on instructions such as `sql:insert` and `sql:query` with an attribute such as `connection="$connection"`; the value of the `connection` attribute is an expression that returns a database connection object.

Next