### Setting up a JDBC connection

This procedure assumes you have set up the JDBC driver as described in the previous task.

Note: The URL format is regulated by the driver itself. That is, different drivers have different URL formats. The format of the driver template in JReport.bat is `jdbc.drivers=JDBCDriverName:JDBCDriverName:...`

where, JDBCDriverName is the JDBC driver name that can be auto-loaded when JReport starts up and ":" is the delimiter between two driver names. JReport will search from the first and find one that can work with the driver, URL, and user name and password in the catalog.

Below is an example of the jdbcdrivers.properties file which specifies an Oracle thin driver and an Interbase thin driver:

`jdbc.drivers=oracle.jdbc.driver.OracleDriver:interbase.interclient.Driver`

To set up a JDBC connection:

1. Create a catalog which contains a default data source, then in the Data tab of the Catalog Browser, expand the node of the data source, right-click the Relational node and choose Add JDBC Connection from the shortcut menu.

   If you want to set up the connection by adding a data source to an existing catalog and then defining the connection on the data source, open the catalog, select any data source contained in it, click the New Data Source button on the Catalog Browser toolbar, then in the New Data source dialog, specify the name of the data source, select the JDBC connection type and click OK.

2. In the Get JDBC Connection Information dialog, specify the options as required. See the dialog.

3. Click OK to set up the connection, and you will be prompted with a message box showing the status of connecting to the JDBC driver.

You have four ways to set up a JDBC connection:

- Setting up by adding an existing connection
  1. In the Get JDBC Connection Information dialog, select the connection from the Connection List. This list contains previously added connection information.
  2. The JDBC URL and JDBC driver name will then appear in the corresponding text box. Click OK.
  Note: The format of the connection information should be JDBC URL / (JDBC Driver Name). For example: jdbc:odbc:jinfonet / (sun.jdbc.odbc.JdbcOdbcDriver).
- Setting up an ODBC connection
  1. In the Get JDBC Connection Information dialog, check the Use ODBC Data Source box. (By default, this checkbox is checked. It indicates that the name you input in the DSN Name field is the ODBC data source name.)
  2. Enter the DSN name in the DSN Name field.
  3. Input the user name and password to enable accessing the database through the ODBC data source, and then click OK.
- Setting up a JDBC connection
  1. In the Get JDBC Connection Information dialog, uncheck the Use ODBC Data Source option.
  2. Check the JDBC Driver option and specify the driver in the field that follows.
  3. In the JDBC URL field, specify the URL of the JDBC driver.
  4. Input the user name and password respectively, and then click OK.

  Note: After entering the JDBC URL, user name and password, you can leave the JDBC Driver field empty and instead supply it in a property file - jdbcdrivers.properties.

- Setting up a connection via the WebLogic 6.1 connection pool
  1. In the Get JDBC Connection Information dialog, uncheck the Use ODBC Data Source option, and then check the Use Connection Pool option.
  2. In the JDBC URL field, specify the URL of the JDBC driver.
  3. Input the user name and password respectively, and then click OK.

Notes:

- Upon the finishing of setting up the connection, the Add Table dialog will be displayed, prompting you to add tables from the database to the connection. If you want to add tables at a later date, click Done.
- When creating any of the above connections, if your database has some special requirements, you can click the Options<< button to modify the options according to your requirements (for details about the options, see Get JDBC Connection Information dialog).

The following examples show how to set up connections via specific JDBC drivers:

- Example 1: Setting up a connection via the Oracle JDBC driver
- Example 2: Setting up a connection via the Sybase JDBC driver
- Example 3: Setting up a connection via WebLogic 6.1 Connection Pool