<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="sql-extension" page="connect" subpage=""/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: sql:connect</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: sql:connect"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>sql:connect</h1>
      <p><code>sql:connect</code> creates a database connection. It has attributes <code>driver</code>,
 <code>database</code>, <code>user</code>, <code>password</code>, and <code>auto-commit</code>
all of which are attribute value templates (so the values can be passed in as parameters).</p>
      <p>The <code>driver</code> attribute names the JDBC driver class to be used. The
database name must be a name that JDBC can associate with an actual database.</p>
      <p>The <code>auto-commit</code> attribute, if present, should take the value "yes" or "no". This
causes a call of <code>connection.setAutoCommit()</code> on the underlying JDBC connection.</p>
      <p>The <code>sql:connect</code> instruction returns a database connection as a value, specifically
a value of type "external object", which can be referred to using the type 
<code>java:java.sql.Connection</code>. Typically
the value will be assigned to a variable using the construct:</p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>
&lt;xsl:variable  name="connection" 
               as="java:java.sql.Connection" 
               xmlns:java="http://saxon.sf.net/java-type"&gt;
  &lt;sql:connect database="jdbc:odbc:testdb" 
               driver="sun.jdbc.odbc.JdbcOdbcDriver" 
               xsl:extension-element-prefixes="sql"/&gt;
&lt;/xsl:variable&gt;
</code>
         </pre>
      </div>
      <p>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 <code>sql:insert</code>
and <code>sql:query</code> with an attribute such as <code>connection="$connection"</code>; the value
of the <code>connection</code> attribute is an expression that returns a database connection object.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="query.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>