Configuring new data sources using wsadmin

You can configure new data sources using the wsadmin scripting tool.

Before you begin

Before starting this task, the wsadmin tool must be running. See the topic about starting the wsadmin scripting client for more information.

In WebSphere® Application Server, any JDBC driver properties that are required by your database vendor must be set as data source properties. Consult Data source minimum required settings, by vendor to see a list of these properties and setting options, ordered by JDBC provider type. Consult your database vendor documentation to learn about available optional data source properties. Script them as custom properties after you create the data source. In the Related links section of this article, click the Configuring new data source custom properties using scripting link for more information.

[z/OS]You can also learn about optional data source properties in the Application Programming Guide and Reference for Java for your version of DB2® for z/OS®, if you use one of the following JDBC providers:
  • DB2 for z/OS Local JDBC Provider (RRS) JDBC Provider (using the DB2 JDBC / SQLJ driver)
  • DB2 Universal JDBC Driver provider

About this task

There are two ways to perform this task; use either of the following wsadmin scripting objects:
  • AdminTask object
  • AdminConfig object
AdminConfig gives you more configuration control than the AdminTask object. When you create a data source using AdminTask, you supply universally required properties only, such as a JNDI name for the data source. (Consult the article JDBCProviderManagement command group for the AdminTask object for more information.) Other properties that are required by your JDBC driver are assigned default values by Application Server. You cannot use AdminTask commands to set or edit these properties; you must use AdminConfig commands.

Procedure

  • Using the AdminConfig object to configure a new data source:
    1. Identify the parent ID, which is the name and location of the JDBC provider that supports your data source.
      • Using Jacl:

        set newjdbc [$AdminConfig getid /Cell:mycell/Node:mynode/JDBCProvider:JDBC1/]
      • Using Jython:

        newjdbc = AdminConfig.getid('/Cell:mycell/Node:mynode/JDBCProvider:JDBC1/')
        print newjdbc
      Example output:
      JDBC1(cells/mycell/nodes/mynode|resources.xml#JDBCProvider_1)
    2. Obtain the required attributes.
      Fast path: For supported JDBC drivers, you can also script data sources according to the same pre-configured templates that are used by the administrative console logic. For more information, see the topic Creating configuration objects using the wsadmin scripting tool.
      • Using Jacl:

        $AdminConfig required DataSource
      • Using Jython:

        print AdminConfig.required('DataSource')
      Example output:
      Attribute   Type
      name	   String
      Tip: If the database vendor-required properties (which are referenced in the topic Data source minimum required settings, by vendor) are not displayed in the resulting list of required attributes, script these properties as data source custom properties after you create the data source.
    3. Set up the required attributes.
      • Using Jacl:

        set name [list name DS1]
        set dsAttrs [list $name]
      • Using Jython:

        name = ['name', 'DS1']
        dsAttrs = [name]
    4. Create the data source.
      • Using Jacl:

        set newds [$AdminConfig create DataSource $newjdbc $dsAttrs]
      • Using Jython:

        newds = AdminConfig.create('DataSource', newjdbc, dsAttrs)
        print newds
      Example output:
      DS1(cells/mycell/nodes/mynode|resources.xml#DataSource_1)
  • Using the AdminTask object to configure a new data source:
    • Using Jacl:

      $AdminTask createDatasource {-interactive}
    • Using Jython:

      AdminTask.createDatasource (['-interactive'])
  • Save the configuration changes.
  • In a network deployment environment only, synchronize the node. For more information, see the topic Synchronizing nodes with the wsadmin tool.

What to do next

To set additional properties that are supported by your JDBC driver, script them as data source custom properties.