Creating a Database Connection

Before you can execute a collection() function in an XQuery, you need to create a database connection. This is part of the process of making the database tables and views available to your XQuery code.

This section covers the following topics:

Supported Databases

Stylus Studio provides support for the following relational databases:

l IBM DB2
l Informix
l Microsoft SQL Server
l MySQL
l Oracle
l PostgreSQL
l Sybase

For specific version support, see http://www.datadirect.com/products/xquery/matrix/ddxquery.htm.

Drivers for most of these databases are bundled with Stylus Studio. For some, like PostgreSQL, for example, you need to specify the classpath for the database driver.

The Connection Settings Dialog Box

In Stylus Studio, you use the Connection Settings dialog box to specify database connection properties.

Settings vary from database to database, but they typically include the following:

l If you are using the PostgreSQL databases, you need to specify the location of the JDBC driver for that database in the Driver Classpath field. (Drivers for other relational databases are bundled with Stylus Studio.)
l You use the Username and Password fields to specify the database user you want to associate with this data source.

Using the Server URL Field

You use the Server URL field to identify the server hosting the database to which you want to connect, the port to use, and any other required or optional parameters. For example, the string used to connect to a Microsoft SQL Server database might look like this:

The specific syntax of the string you enter in the Server URL field varies based on database type. Consult your database documentation for information regarding connectivity syntax and optional parameters.

How to Create a Database Connection

To create a database connection:
1. Display the File Explorer window if it is not already open (View > File Explorer).
2. In the File Explorer window, right-click the RelationalDB icon and select New Server from the short-cut menu.
Stylus Studio displays the Connection Settings dialog box.
4. Did you select a database in the Database Type field for which you must specify a driver?
5. When you select a database in the Database Type field for which you must specify a driver, the Driver Classpath field becomes enabled. To specify the driver location:
a. Click the more button ( ).
The Set Classpath for the JDBC Driver dialog box appears.
b. Click the browse folders ( ) button.
A new entry field appears in the Locations list box. Two buttons appear to the right of the entry field.
c. To add a JAR file to the classpath, click the browse jar files button ( ).
Stylus Studio displays the Browse for Jar Files dialog box.
To add a folder to the classpath, click the browse folders button ( ).
Stylus Studio displays the Browse for Folder dialog box.
d. When you have located the JAR file or folder you want to add to the classpath, click OK.
The file appears in the Locations list box of the Set Classpath for the JDBC Driver dialog box.
e. Click OK.
The JAR file or folder appears in the Driver Classpath field of the Connection Settings dialog box.
6. Click OK on the Connection Settings dialog box.
The server connection appears in the File Explorer window.
 
Free Stylus Studio XML Training: