I reposting my question : Chris Thanks for all your help . Could you please suggest me where to specify this datasource in ejb-jar.xml & jndi name with datasource in ejb-weblogic-jar.xml Following is my ejb-jar.xml: <?xml version="1.0"?> <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'> <ejb-jar> <enterprise-beans> <session> <ejb-name>statelessSession</ejb-name> <home> myapp.MYAPPWebServiceHome</home> <remote> myapp.MYAPPWebService</remote> <ejb-class> myapp.MYAPPWebServiceBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> </enterprise-beans> <assembly-descriptor> <container-transaction> <method> <ejb-name>statelessSession</ejb-name> <method-intf>Remote</method-intf> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> <container-transaction> </assembly-descriptor> </ejb-jar> following is my ejb-weblogic-jar.xml : <?xml version="1.0"?> <!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN' 'http://www.bea.com/servers/wls510/dtd/weblogic-ejb-jar.dtd'> <weblogic-ejb-jar> <weblogic-enterprise-bean> <ejb-name>statelessSession</ejb-name> <caching-descriptor> <max-beans-in-free-pool>100</max-beans-in-free-pool> </caching-descriptor> <jndi-name>stateless.MYAPPWebServiceHome</jndi-name> </weblogic-enterprise-bean> </weblogic-ejb-jar>
Following is my code in the ejb method: Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL, "t3://hostName:7001"); // Get a context for the JNDI look up ctx = new InitialContext(ht); javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("mydataSource-OracleThinDriverPool"); conn = ds.getConnection(); Thanks, smita
You don't NEED to specify the datasource in your ejb descriptors. It is just a way to avoid hardcoding the datasource's JNDI name in your code. If all of your EJBs use the same datasource and there is no immediate need to use separate datasource that I would put the JNDI name directly in code. Create a helper class for retrieving the connection and have it coded there in one place. I have created a class to this in my projects. Here is a simple class for this purpose. It uses another class to get an initial context went is not shown:
Usage looks like this:
The thing that I like is that I now have strong compile-time checking on my connection pool usage. If you use the DD and you make a typo in 1 of your 10 ejbs, then you won't know until the first time you access that bean. This way you have one central place to change all your connection pool configuration and if it works for one, it will work for all. The other benefit is that if you want to know where a connection pool is being used, comment out one line and let the compiler find all the dangling references. Of course, this means that a change in configuration means a change in code... but I can live with that. If it turns out to be a bad idea in the future than I will just refactor it out!
Imports, comments, and additional code has been left out to protect the innoccent.
Thank you very much. If you don't mind could you please advise what is the diffrence between Txdatasource and datasource.
I have diffrent databases on diffrent machines. All i need to do is to pass the url,sid etc for each of the machine/database and get the data. for ex> one is url :jdbc racle:thin:@mydevelopmentmc:1521 EMO user: abc password:abc my another url is url :jdbc racle:thin:@mytestmc:1521:TEST user: abctest password:abctest I am planning to create two connection pools one for each also two corresponding data sources. Is there any better solution.please advise Thanks again smita
I am a man of mystery. Mostly because of this tiny ad:
a bit of art, as a gift, the permaculture playing cards