### Configuring the server database when integrating with an application server

JReport Server supports connecting an RDBMS to access its system data via JDBC. The JDBC configuration information is stored in the file dbconfig.xml in `<install_root>\bin`. You can create a database connection according to this configuration file. Also, with the Java EE Data Source Support feature, in a Java EE environment, JReport Server can get the predefined javax.sql.DataSource by JNDI APIs.

Here, the term dsInfo is used to indicate where JReport Server can obtain the JDBC connection information. It is a key-value pair. The name and value for dsInfo are defined as follows:

- The name should be: jreport.datasource.<dbname>, where, <dbname> is JReport Server's inner database name. It must be systemtables, realmtables, or profile. For example, the dsInfo name is jreport.datasource.realmtables.
- The value should be in the form of a URL. There are three protocols supported by JReport Server:
  - `file:///absolute_path_of_config_file`

    For example: `file:///JReport/Server/bin/dbconfig.xml`

  - `jdbc://[<jdbc-user:jdbc-password>@]<jdbc-url>[#<attribute-name=attribute-value>,]`

    For example: `jdbc://user:password@jdbc:odbc:jreport-realmtables#driver=sun.jdbc.odbc.JdbcOdbcDriver`

  - `jndi://[<jdbc-user:jdbc-passoword>@]datasource_name[#<attribute-name=attribute-value>,]`

    For example: `jndi://jdbc/jreport-realmtables`

The dsInfo can be specified in several places or levels, such as VM properties, ejb-jar.xml, web.xml and <install_root>\bin\dbconfig.xml. The sequence to load the information is:

VM system environment > ejb-jar.xml (EAR mode) > web.xml (WAR mode) > dbconfig.xml.

Notes:

- The jreport.ear file that JReport Server creates does not specify any Java EE information. By default it will load from the dbconfig.xml file.
- There is a limitation in WebSphere. JReport Server's dsInfo can be configured to the WEB-INF/web.xml with JNDI name but not RESOURCE name. JBoss works fine for either one.
- Do not use reporthome, @ or # in the JNDI name or Resource name.

The following shows specifying the dsInfo in web.xml, ejb-jar.xml, and dbconfig.xml respectively:

#### Specifying data source in web.xml (for the WAR mode)

When integrating the JReport Server in a WAR package, you can specify the dsInfo in the WEB-INF/web.xml file using the `<env-entry></env-entry>` or `<context-param></context-param>` tags. However, the use of the `<env-entry></env-entry>` tags is the recommended way since the tags are also supported in ejb-jar.xml (if you call the Server API in your EJB).

The following is an example of specifying the dsInfo in WEB-INF/web.xml using the `<env-entry></env-entry>` tags:

    <web-app>
        ...

        <env-entry>
            <env-entry-name>jreport.datasource.realmtables</env-entry-name>
            <env-entry-value>jndi://java:/resource-name</env-entry-value>
            <env-entry-type>java.lang.String</env-entry-type>
        </env-entry>
    </web-app>

The following is an example of specifying the dsInfo in WEB-INF/web.xml using the `<context-param></context-param>` tags:

    <web-app>
        <context-param>
            <param-name>jreport.datasource.realmtables</param-name>
            <param-value>jndi://datasource_name_which_is_predefined</param-value>
        </context-param>
        ...

    </web-app>

#### Specifying data source in ejb-jar.xml or web.xml (for the EAR mode)

When the JReport Server is used with APIs by EJBs, you can specify the dsInfo either in the file ejb-jar.xml in `/META-INF` or web.xml in `/WEB-INF`.

For information about specifying a data source in the web.xml file, see section Specifying data source in web.xml (for the WAR mode).

Note: If the dsInfo is stored in a Web module, you should add the JReport Server context listener to the WEB-INF/web.xml file. Here is an example:

    <web-app>
        <listener>
            <listener-class>
                 jet.server.servlets.JRServerContextListener
                 </listnener-class>
        </listener>
        ...
    </web-app>

You can specify the dsInfo in the META-INF/ejb-jar.xml file using the `<env-entry></env-entry>` tags. For example, here is an EJB named firstEJB which creates the JReport Server instance. You can add the `<env-entry></env-entry>` tags to the EJB's configuration file - META-INF/ejb-jar.xml as follows:

    <ejb-jar>
        <enterprise-beans>
            <session>
                <ejb-name>firstEJB</ejb-name>
                ...
                <env-entry>
                    <env-entry-name>jreport.datasource.realmtables</env-entry-name>
                    <env-entry-value>jndi://java:/resource_name</env-entry-value>
                    <env-entry-type>java.lang.String</env-entry-type>
                </env-entry>
            </session>
            ...

        </enterprise-beans>
        ...

    </ejb-jar>

#### Specifying data source in dbconfig.xml

By default, JReport Server assumes that jreport.datasource.realmtables=file:///${rpthome}/bin/dbconfig.xml. You can specify either a JDBC or JNDI data source using the `<datasource></datasource>` tags in the dbconfig.xml file.

For details about configuring the JDBC data source, see Configuring the server database in a standalone environment.

The following is an example of specifying the JNDI data source:

    <?xml version="1.0" encoding="UTF-8"?>
    <dbconfig>
        <workspace name="systemRealm">
            <database name="systemtables">
                <datasource>jndi://datasource-name</datasource>
            </database>
        </workspace>
        <workspace name="defaultRealm">
            <database name="realmtables">
                <datasource>jndi://datasource-name</datasource>
            </database>
        </workspace>
    </dbconfig>