Example: Accessing data using IBM extended APIs for connections

If your application runs with a shareable connection that might be shared with other container-managed persistence (CMP) beans within a transaction, it is recommended that you use the WAS extended APIs to get the connection. When you use these APIs, one cannot port your application to other application servers.

We can access an extended API in your JDBC application. Instead of using the DataSource interface, you use the WSDataSource interface. The following code segment illustrates how to get the connection.


import com.ibm.websphere.rsadapter.*;

... 

// Create a JDBCConnectionSpec and set connection properties. If this connection is shared with
the CMP bean, make sure that the isolation level is the same as the isolation level that is mapped by the Access Intent defined on the CMP bean. 

JDBCConnectionSpec connSpec = WSRRAFactory.createJDBCConnectionSpec(); 

connSpec.setTransactionIsolation(CONNECTION.TRANSACTION_REPEATABLE_READ); 

connSpec.setCatalog("DEPT407");


//Use WSDataSource to get the connection 

Connection conn = ((WSDataSource)datasource).getConnection(connSpec);




 

See Also


Resource adapter
Unshareable and shareable connections

 

See Also


Extensions to data access APIs