My web project connects to a database. WebSphere server can provide pooled connection as datasource. In my application, I just simply get the connection by lookup through the context:
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(dataSourceUri);
con = ds.getConnection();
Using this way, I can let container manages the connection and security. I just simply retrieve the connection from my code. Direct resource lookup is deprecated in WebSphere 6 for security reasons. Now we have to look up the datasource through resouce reference (i.e., indirect lookup). Application will specify the resource reference that the application will lookup in the deployment descriptor. The container can link the resource reference to resource by confiugration. This way, a data source is not exposed to any application.
We have to let application tell which resource reference it is going to lookup first. To do this, cllick the Deployment Descriptor in the web project and click the References tab. Add a new resource reference. For data resources, set type to javax.sql.DataSource. Set authentication to container. To make it easier to work with local testing environment, we can set the JNDI name tha the resource reference should bind to under WebSphere Bidings. Set JNDI Login Configuration to None.
In the next part, we will specify how to configure the resouce reference in the admin console.