Configuring Connections
DataDirect XQuery uses fn:collection() to access relational data. DataDirect XQuery uses XQJ to specify the required database connections and associate the names specified by fn:collection() with the database tables.
Using XQJ, you create a connection from an XQDataSource instance. The fully qualified class name of the DataDirect XQuery XQDataSource implementation is:
com.ddtek.xquery.xqj.DDXQDataSource
The following class provides additional properties for configuring connections to multiple databases:
com.ddtek.xquery.xqj.DDXQJDBCConnection
Specifying Connection Information
You can specify connection information to relational data sources using either of the methods shown in the following examples.
Example 1: Using a DDXQDataSource Instance to Specify Connection Information Explicitly
DDXQDataSource ds = new DDXQDataSource(); ds.setJdbcUrl("jdbc:xquery:sqlserver://server1:1433;databaseName=stocks");Example 2: Using the Java Naming and Directory Interface (JNDI)
Context ctx = new InitialContext(); DDXQDataSource ds = (DDXQDataSource)ctx.lookup("holdings_ds"); XQConnection conn = ds.getConnection("myuserid", "mypswd");See the JNDIDataSource example for a complete code sample of how to save and load a DataDirect XQuery DDXQDataSource using a JNDI provider.
After specifying connection information using with either DDXQDataSource or JNDI, the getConnection() method can be invoked to return an XQJ connection to the database and, optionally, specify the user name and password for the connection: