I am having difficulty connecting to a DataSource (DB2) in WebSphere v7 (Developers edition). I am fairly new to WebSphere, and to EJB programming. I have created an EAR file containing:
1. A WAR file
2. An EJB-JAR file
3. Utility Jars
The EJB Jar has a Session bean and a POJO that connects (with limited success) to DB2 to execute a set of database queries. The name of my database is "tether". If I attempt to connect using the following code:
InitialContext initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup("jdbc/tether");
con = ds.getConnection();
I get the following error:
Null userid is not supported. ERRORCODE=-4461, SQLSTATE=42815DSRA0010E: SQL State = 42815, Error Code = -4,461
However, if I use the following form of the getConnection() method:
con = ds.getConnection("user", "pass");
I get a connection to DB2 and can retrieve records. However, I do not want to hard code user names and passwords, for obvious reasons. Accordingly, I setup a J2C Authentication Alias, and tested it directly from a servlet (within the WAR file), using the following XML in my web.xml deployment descriptor:
jdbc/TetherRef
javax.sql.DataSource
CONTAINER
Shareable
and the following XML in my ibm-web-bnd.xmi file:
and in ibm-web-ext.xmi :
This test worked fine. I then re-factored my test setup such that the JSP/Servlet layer interfaced to a Session bean which used a POJO helper class to do the database stuff (all in JDBC). This configuration only works if I specify the username/password on the getConnection() call. The J2C Authentication Alias is not being used (or found).
I assume that I have to setup a resource reference in the ejb-jar.xml deployment descriptor, and the ibm-ejb-jar-bnd.xml and ibm-ejb-jar-ext.xml files. However, this step has me absolutely stymied. Nothing that I have tried has been able to retrieve a connection without hard coding the username/password.
Please note that I do not have RAD, and cannot yet afford the $2,500 per seat license (we are a small startup company), so configuration solutions involving RAD do me no good. Currently, I use ANT to build and deploy. I also use ANT to configure WebSpehere (creating the DataSource, creating the Alias, etc...)
Any suggestions? All help will be appreciated.
Thanks
Akash
Yes, I can test the connection successfully from the Admin console and using a Jython script.
Mike Laris
Thanks
Akash
Yes, tried that. I restart the AppServer as a matter of protocol when deploying a new test case. Perhaps not always strictly necessary, but it does eliminate the possibility of certain problems.
Mike Laris