File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes Connecting to Oracle data source from EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Connecting to Oracle data source from EJB" Watch "Connecting to Oracle data source from EJB" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to Oracle data source from EJB
 
Similar Threads
Configuration of WebSphere JMS MQ Provider
Error "failed to create MQQueueManager" In WAS5.0
DataSource via JNDI in WSAD 5
WAS 5 - Error while connecting to Oracle datasource:
Error in getConnection using Datasource