Using a Source Configuration File
How a typical source configuration file looks depends on whether your queries access XML or relational data sources. This section provides information about using source configuration files to configure connections.
Configuring Connections for XML Data Sources
If your Java application executes queries that access only XML data sources, a typical source configuration file would look like the following example:
<?xml version="1.0" ?> <XQJConnection xmlns="http://www.datadirect.com/xquery"> <baseUri>file:///c:/programs/ddxq/examples/</baseUri> </XQJConnection>The baseUri element in the preceding example specifies the base URI used to resolve relative URIs in fn:doc(). See Elements of the Source Configuration File for a description of all elements that can be specified in a source configuration file.
Configuring Connections for Relational Data Sources
A minimum source configuration file specifying connection information to a single relational database, Microsoft SQL Server, in this case, looks like the following example:
<XQJConnection xmlns="http://www.datadirect.com/xquery"> <JDBCConnection name="example_connection_name"> <url>jdbc:xquery:sqlserver://localhost:1433</url> </JDBCConnection> </XQJConnection>See Examples of Source Configuration Files for more examples of source configuration files.
See Elements of the Source Configuration File for a description of all the elements that can be specified in a source configuration file.
Referencing a Source Configuration File
To reference a DataDirect XQuery source configuration file in your Java application, construct a DDXQDataSource instance, as shown in the following XQJ code, where
path_to_source_configfileis the path to the source configuration file.FileInputStream is = null; DDXQDataSource ds = null; try { is = new FileInputStream("path_to_source_configfile"); ds = new DDXQDataSource(is); } finally { if (is != null) is.close(); } XQConnection conn = ds.getConnection("myuserid", "mypswd");You can override the connection information in the source configuration file by setting that information explicitly using XQJ. For example, the URL set explicitly in the following XQJ code overrides any URL set in the referenced source configuration file:
FileInputStream is = null; DDXQDataSource ds = null; try { is = new FileInputStream("DDXQ_configfile.xml"); ds = new DDXQDataSource(is); } finally { if (is != null) is.close(); } ds.setJdbcUrl("jdbc:xquery:sqlserver://server1:1433;databaseName=stocks"); XQConnection conn = ds.getConnection("myuserid", "mypswd");