Configure new data sources using wsadmin
We can configure new data sources using wsdmin.sh.
Before starting this task, wsadmin.sh must be running. See the topic Starting the wsadmin scripting client for more information.
In WebSphere Application Server, any JDBC driver properties required by the database vendor must be set as data source properties. Consult the article Data source minimum required settings, by vendor to see a list of these properties and setting options, ordered by JDBC provider type. Consult the database vendor documentation to learn about available optional data source properties. Script them as custom properties after we create the data source. In the Related links section of this article, click the Configure new data source custom properties link for more information.
(zos) We can also learn about optional data source properties in the Application Programming Guide and Reference for Java for the 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
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 creating 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 (AdminTask) for more information.) Other properties required by the JDBC driver are assigned default values by Application Server. We cannot use AdminTask commands to set or edit these properties; use AdminConfig commands.
- Use the AdminConfig object to configure a new data source:
- Identify the parent ID, which is the name and location of the JDBC provider that supports the data source.
Jacl:
set newjdbc [$AdminConfig getid /Cell:mycell/Node:mynode/JDBCProvider:JDBC1/]
Jython:
newjdbc = AdminConfig.getid('/Cell:mycell/Node:mynode/JDBCProvider:JDBC1/') print newjdbc
Example output:
JDBC1(cells/mycell/nodes/mynode|resources.xml#JDBCProvider_1)
- Obtain the required attributes.
Fast path: For supported JDBC drivers, we can also script data sources according to the same pre-configured templates used by the console logic. For more information, see the topic Creating configuration objects using wsdmin.sh.
Jacl:
$AdminConfig required DataSource
Jython:
print AdminConfig. required('DataSource')
Example output:
Attribute Type name StringIf 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 we create the data source.
- Set up the required attributes.
Jacl:
set name [list name DS1] set dsAttrs [list $name]
Jython:
name = ['name', 'DS1'] dsAttrs = [name]
- Create the data source.
Jacl:
set newds [$AdminConfig create DataSource $newjdbc $dsAttrs]
Jython:
newds = AdminConfig.create('DataSource', newjdbc, dsAttrs) print newds
Example output:
DS1(cells/mycell/nodes/mynode|resources.xml#DataSource_1)
- Use the AdminTask object to configure a new data source:
Jacl:
$AdminTask createDatasource {-interactive}
Jython:
AdminTask.createDatasource (['-interactive'])
- Save the configuration changes. See the topic Saving configuration changes with wsadmin.sh for more information.
- In a network deployment environment only, synchronize the node. For more information, see the topic Synchronizing nodes with wsadmin.sh.
What to do next
To set additional properties that are supported by the JDBC driver, script them as data source custom properties.
Related tasks
Configure new data source custom properties using wsadmin Create configuration objects using wsdmin.sh Use the wsadmin scripting AdminConfig object for scripted administration Synchronize nodes using wsdmin.sh Start the wsadmin scripting client Saving configuration changes with wsadmin.sh
Data source minimum required settings, by vendor Commands for the AdminConfig object WebSphere Application Server data source properties JDBCProviderManagement command group for AdminTask object