Accessing an existing Java EE data source resource
The same DataSource MBean and JDBCProvider MBean programming model used to access a WebSphere Application Server managed data source (defined in scripting or the Integrated Solutions Console) can be used to access a Java EE data source resource defined in the application with the DataSourceDefinition annotation or with the <data-source> element of the deployment descriptor. This feature maintains compatibility with existing scripts, simplifying the management of our resources.
This task illustrates through examples how an MBean represents a Java EE data source resource.
Use the DataSource MBean
Use the name field of the DataSource MBean as the JNDI name with special characters, as follows:
JNDI name = java:module/env/jdbc/myDataSource name = java.module/env/jdbc/myDataSourceAdditional fields for application, module, and component are included whenever applicable; for example:
WebSphere:type=DataSource,name=java.module/env/jdbc/myDataSource,application=MyApp,module=MyModule,*Use these values, we can query for the MBean for a particular application, as follows:
WebSphere:type=DataSource,name=java.app/env/myDataSource,application=MyApp,*or query for an identically named java:app JNDI name in a different application as follows:WebSphere:type=DataSource,name=java.app/env/myDataSource,application=MyOtherApp,*A query that omits the application field returns both MBeans as follows:
WebSphere:type=DataSource,name=java.app/env/myDataSource,*In the web module, the Java EE specification defines java:comp to be the same namespace as java:module. Therefore, MBean queries for data sources defined in the web module should not include the component field.
To query for java:comp/env/ds1 defined in the web module, use the following:
WebSphere:type=DataSource,name=java.comp/env/ds1,application=MyApp,module=MyModule,*To query for java:comp/env/ds2 defined in an EJB module, use the following:
WebSphere:type=DataSource,name=java.comp/env/ds2,application=MyApp,module=MyModule,component=MyBean,*To query for java:app/env/myDataSource defined in an application named yApp, use the following:
WebSphere:type=DataSource,name=java.app/env/myDataSource,application=MyApp,*To query for an identically named java:app JNDI name in a different application named MyOtherApp, use the following:
WebSphere:type=DataSource,name=java.app/env/myDataSource,application=MyOtherApp,*The application, module, and component parameters can also be used to perform a general query for all data sources defined in a particular application; for example:
WebSphere:type=DataSource,application=MyApp,*In addition to the DataSource MBean for each Java EE data source, there is also a JDBCProvider MBean. The name of the JDBCProvider MBean is the name of the DataSource MBean prefixed with JDBCProvider_, for example:
WebSphere:type=JDBCProvider,name=JDBCProvider_java.module/env/datasource3,application=MyApp,module=MyModule,*The JDBCProvider MBean has one data source associated with it, as illustrated in the following example:
WebSphere:type=DataSource,name=java.module/env/datasource3,application=MyApp,module=MyModule,*
Configure a JDBC provider and data source Data source minimum required settings, by vendor