1. Home
  2. Knowledge Base
  3. Administration
  4. Change Variable Data Sources

Change Variable Data Sources


The data source is the definition of the database connection which includes:

  • IP address
  • DB type
  • DB driver name
  • User and password
  • Special considerations, such as the library list

Multiple data sources can be defined in the global Data Source Configuration file (/mrcjava/WEB-INF/classes/mrc-spring-context.xml). In each dictionary (/mrcjava/WEB-INF/classes/DD/mrc_servlet_config.xml), you can assign a single data source for all applications within that dictionary with the datasource parameter. You can override that default data source selection at the program level by specifying another data source in the application properties file (/mrcjava/WEB-INF/classes/DD/IXXXXXp.xml).

Sometimes, though, as the application designer, you might prefer to set the data source conditionally. An example of that would be a case where you would like to allow the end user to select a company to work in. In these cases, it is possible to present the user with several companies that they may work in. Behind the scenes, the user’s company selection will set the data source for the current browser session. The differences in the data source might be minor, different only because of the library list definition, or major, with different IP and DB types. Subsequent applications, then, will use the selected data source instead of a pre-defined one for the current browser session.

In the example above, you can see that despite the thousands of records, the user CROWLEY can only see the 2 companies (or data connections) to which he is assigned. Clicking on the Library name will set the library for the user’s session.

Here are the steps to complete this process:

  1. Define your separate data sources.
    1. Define the id parameter as a value that can be derived in the Data Source Selection screen. Use “as400_remote_LIB10” and “as400_remote_LIB20” for example, if choosing between company 10 and 20. The DB prefix such as “as400_remote_” or “as400_local_” is required. The suffix will make it unique to the desired data source.
  2. Configure your Data Dictionary to enable variable data sources.
    1. Copy file mrcdatasource.xml from /mrcjava/mrcclasses/ into the DD directory.
    2. Configure the entry_url with the Data Source Selection screen that you will generate in the next step, such as DD.I00010s.
    3. Define any applications that should be excluded from the variable data source logic, instead of using the default data source connection. Use the applications tag for that purpose, with an app entry for each application to exclude. If you create the Data Source Selection screen in that same Data Dictionary, be sure to exclude that application, or you will cause an infinite loop of redirection.
  3. Add the variable datasource servlet entry to the web.xml.
    1. Edit the web.xml in a text editor from /mrcjava/WEB-INF/ and add the following entry at the end of the file before the </web-app> tag:
    2. Once done, make sure to save the file and restart Tomcat.

    *Note As the web.xml is a global file, this step only needs to be done the very first time the Variable Datasources is being configured, and does not need to repeated per dictionary. Before adding to the web.xml, make sure this entry does not already exist by doing a search for ‘SetDataInSession’.

  4. Create a retrieval application that will serve as the Data Source Selection screen.
    1. This might be built over a file that selects records by user employing the secure_by user technique or it might be a list of the same options available to all users.
    2. Paint the application to include a link on every row like the following to set the data source:
      1. SetDataInSession?data_src=as400_remote_CO1&redirect_url=DD.I00100s
    3. The syntax, including the href tag and the text, might look like this:<a href="SetDataInSession?data_src=as400_remote_LIB10&redirect_url=DD.I00100s">Company 10</a>
    4. End User Screen Flow:
      1. mrcSignon (end user authentication, optional)
      2. Data Source Selection (DD.I00010s, for example)
      3. DD.I00100s (application or menu of applications)

If the data source definitions will only be different due to the library list setup, then it will be necessary to configure the applications to avoid hard-coding the data library name in the SQL statement. That is done by setting the tablename_fmt parameter to “1” (Table name only) in the Data Dictionary properties file: mrc_servlet_config.xml. This will instruct the applications to use only the table name in the SQL, not the data library name which was used at development time, allowing the library list to determine which data library to use. If you have any individual applications that should use their data library name in the SQL statement, you can add that parameter at the program level and set it appropriately there.

Updated on September 29, 2021

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support