| Author |
Connecting to Oracle data source from EJB
|
chandubcs
Ranch Hand
Joined: Jun 03, 2001
Posts: 47
|
|
Hi, I am trying to connect to Oracle data source from EJB in WebSphere 5. The same code is working in WSAD 5.1. Actually, I am using JSP to call EJB to access Oracle DB using Oracle datasource. The EJB code to get Oracle DB connection is like: ------------------ InitialContext ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("jdbc/OraDSN"); System.out.print("DataSource is: "+ds.toString()); Connection Conn = ds.getConnection("Username","Password"); ------------------ I have created "jdbc/OraDSN" in WebSphere server. One thing to be observed is when I try to use the same code in a JSP, its working and connecting to database, but its not connecting from a EJB. The error I got was: J2CA0046E: Method createManagedConnctionWithMCWrapper caught an exception during creation of the ManagedConnection for resource jdbc/WebDLR_JNDI, throwing ResourceAllocationException. Original exception: com.ibm.ws.exception.WsException: Subject was not null but no valid credentials were found............................... 54667916 ConnectionMan E J2CA0020E: The Connection Pool Manager could not allocate a Managed Connection: javax.resource.spi.ResourceAllocationException: Caught ResourceException thrown during creation of the ManagedConnection........................ java.sql.SQLException: DSRA9002E: ResourceException with error code null: javax.resource.spi.ResourceAllocationException: Caught ResourceException thrown during creation of the ManagedConnection. I am using JSP, EJB 2.0 with CMP, Stateless session bean to connect to DB, ORacle thin driver, Oracle 8.1.7, WS 5.0, WSAD 5.1 Please let me know if anyone has a solution for my issue. Thanks, Chandra
|
 |
chandubcs
Ranch Hand
Joined: Jun 03, 2001
Posts: 47
|
|
I figured out the solution. We need to create a "J2C Authentication Data Entries" with database username/password for a Oracle Data Source name and assign that to the Oracle DSN. The process is: Go to Admin console of WebSphere, click Resources - JDBC Providers - select DSN - click Data Sources - click on DSN name - in the bottom, select "J2C Authentication Data Entries" - click NEW button - Enter some alias name and give username & password for that DSN and click apply/OK. Then click Resources - JDBC Providers - select DSN - click Data Sources - click on DSN name - in the bottom, select the newly created alias name for "Component-managed Authentication Alias" and "Container-managed Authentication Alias" and click apply/OK, save it and restart the server.
|
 |
 |
|
|
subject: Connecting to Oracle data source from EJB
|
|
|