We are having an issue in getting Connections from a DataSource. We are using WebSphere 3.5.3, although have seen this problem since 3.5.
1) We get our DataSource from JNDI using (TDB2 is our DataSource name setup in WebSphere:
Object o = getInitialContext().lookup("jdbc/TDB2"); We then narrow this to a DataSource.
2) Using this DataSource, we get a Connection:
java.sql.Connection c = dataSource.getConnection(userName, password);
However, in order to use this, we need to get the username and password from somewhere, introducing a security risk.
When setting up DataSources on EJBs (in WebSphere), a DataSource is associated with a Bean, and a USerName and Password is associated with it. I would like to then use this DataSource and get a Connection from it, but I have 2 problems (probably more, but I have not encountered them yet):
a) How do I get the DataSource associated with the specific EJB Bean?
b) How do I get the Connection from that DataSource? If I use the empty parm version: "dataSource.getConnection()", it does not use the correct userName/password (or I could be using the wrong DataSource) - I do not get a Connection.
Thanks for any insight!