sql:connect

Creates a database connection.

Attributes

driver?

{ eqname }

The name of the JDBC driver class to be used. From Saxon 10.5 this is no longer needed, and is ignored if specified.

database

{ eqname }

The name (URL) of the database. Must be a name that JDBC can associate with an actual database. An example might be jdbc:derby:codejava/webdb;create=true.

user?

{ expression }

The user name if required for connection (and if not included in the database URL).

password?

{ expression }

The password if required for connection (and if not included in the database URL).

auto-commit?

{ boolean }

If the value is yes, then this causes a call of connection.setAutoCommit() on the underlying JDBC connection.

Details

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" 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.