Unable to locate the DataSource in Application Scope Connection pooling

Hi,

I am trying to create the DataSourceFactory in Weblogic8.1. I was able to create the pool successfully But when I am trying to connect the DatasourCe through Java Programme getthing the exception " Unable to locate the Datasource".
I am trying to connect through

                                               Hashtable ht = new Hashtable();
                  ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");  
                  ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
                  Context ctx = new InitialContext(ht);
                  DataSource ds = (DataSource) ctx.lookup("PMATDS");
                  Connection conn = ds.getConnection();


One more thing I am getting the exception in "Descriptor Tab" and unable to view the DataSource Name in  JNDI tree

java.lang.NoSuchMethodException: couldn't find getter for 'RemoveInfectedConnectionsEnabled' on weblogic.management.console.info.ResourcePoolDynamicWrapper
      at weblogic.management.console.utils.ReflectUtils.getGetter(ReflectUtils.java:287)
      at weblogic.management.console.info.ReflectingAttribute.getGetter(ReflectingAttribute.java:73)
      at weblogic.management.console.info.ReflectingAttribute.(ReflectingAttribute.java:52)
      at weblogic.management.console.info.ReflectingAttribute.(ReflectingAttribute.java:45)
      at weblogic.management.console.info.HelpableReflectingAttribute.(HelpableReflectingAttribute.java:26)
      at weblogic.management.console.info.DDAttribute.(DDAttribute.java:14)
      at weblogic.management.console.webapp._domain.__jdbcpoolcomponent._jspService(__jdbcpoolcomponent.java:973)
      at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
      at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
      at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
      at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
      at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:301)
      at weblogic.servlet.jsp.PageContextImpl.forward(PageContextImpl.java:150)
      at weblogic.management.console.actions.ForwardAction.perform(ForwardAction.java:35)
      at weblogic.management.console.actions.internal.ActionServlet.doAction(ActionServlet.java:173)
      at weblogic.management.console.actions.internal.ActionServlet.doGet(ActionServlet.java:91)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
      at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
      at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
      at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
      at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
      at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
      at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
      at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

Can u  please some guide me to configure the data source connection pool.

Thanks in Advance.
Manoj

ManojKBeheraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kiranhkCommented:
go to Services--> JDBC-->Data Sources on the admin console http://localhost:7001/console
Create a datasource and then create a connection pool to associate the datasource with the pool.


http://e-docs.bea.com/wls/docs81/ConsoleHelp/jdbc.html
0
petmagdyCommented:
use resource reference instead it is simply like that:

1- suppose that ur Weblogic Datasource JNDI name is myapp-dataSource-myds


2- in your code just lookup like this:

        DataSource dataSource = null;
         InitialContext initCtx = new InitialContext();
         dataSource = (DataSource)initCtx.lookup("java:comp/env/jdbc/anynameDS");
         connection = dataSource.getConnection();


3- in ur web.xml

add this section:

      <resource-ref>
        <res-ref-name>jdbc/anynameDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>


 4- in ur weblogic.xml put this:

    <reference-descriptor>
      <resource-description>
        <res-ref-name>jdbc/anynameDS</res-ref-name>
      <jndi-name>myapp-dataSource-myds</jndi-name>
      </resource-description>
    </reference-descriptor>

0
ManojKBeheraAuthor Commented:
Hi,

I am going to create DataSourceFactory not DataSource . Is it the setting is ame in both in same..
Please let me know.

 go to Services--> JDBC-->Data Sources  create only Data source  But I am trying to create  a DataSourceFactory to create a Application Source connection POOL..

Please let me know your comment.
Its urgent

Thanks
Manoj
 
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

ManojKBeheraAuthor Commented:
I am trying to create the DatSourceConnectionPool Not DataSource bind with Connection Pool... So I Cannot create a coonetion pool connected with DatSource.

Please let me know if any thing else is required..

Thanks
Manoj

0
petmagdyCommented:
Manoj if you want to use the pool u must first create a datasource that references that pool and then use the JNDI name of this DS to be mapped to a resource reference inside ur J2EE application as i explained in my comment before, by that u will get connections to the pool u created, this is the standard way

please try it and tell me

good luck
0
ManojKBeheraAuthor Commented:
Hi petmagdy,

I am trying to create a DataSourceFactory which is called Data Source Application Poolling nt the Data Source + Connection Pooling. If you check your Weblogic console below to the Data source you can find  DataSourceFactory , For that we need not to create and connection pool + datasource combination.

For DataSource Factory we need a weblogic-application.xml file which is going to store in META-INF dir along with application.xml.

And we need a DataSourceFactory which contain the factory name and with factory name it will look into the weblogic-application.xml file. this DataSourceFactory is  application specific not the weblogic specific.
After createing the datasource u can deploy and you can  see a sign for Data sorce Factory along with the all the jar files in the application tab in weblogic console.

Please let me know if you need any more clarification

Manoj

0
petmagdyCommented:
Ok I got it

please try add those 2 env. parameters the weblogic admin/user, maybe authentication is required to lookup the DatasourceFactory

          ht.put(Context.SECURITY_PRINCIPAL, user);
          ht.put(Context.SECURITY_CREDENTIALS, password);

Good luck


0
petmagdyCommented:
Sorry Manoj

can u send me ur datasource and datasource dactory configuration in config.xml of ur Weblogic instance?

providing user/password may not be the solution
0
petmagdyCommented:
Sorry again manoj please neglect my last comment

from ur weblogic-application.xml get the DataSource Name (not the factoy name) suppose to be "PMATDS" and if u r openining the factory connections from Web module do this:

1- in ur code
       DataSource dataSource = null;
         InitialContext initCtx = new InitialContext();
         dataSource = (DataSource)initCtx.lookup("java:comp/env/jdbc/anynameDS");
         connection = dataSource.getConnection();


3- in ur web.xml

add this section:

      <resource-ref>
        <res-ref-name>jdbc/anynameDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>


 4- in ur weblogic.xml put this:

    <reference-descriptor>
      <resource-description>
        <res-ref-name>jdbc/anynameDS</res-ref-name>
        <jndi-name>PMATDS</jndi-name>
      </resource-description>
    </reference-descriptor>


I am quite sure this will work, don't use JNDI lookup use local reference lookup u will find my solution compatible to Weblogic documentation as refered to Configuring and Using Application-Scoped JDBC Connection Pools at:

http://e-docs.bea.com/wls/docs81/jdbc/programming.html#1050534




0
ManojKBeheraAuthor Commented:
Hi,

We are connecting the weblogic-application.xml
through config.xml configuration

 <JDBCDataSourceFactory DriverClassName="weblogic.jdbc.db2.DB2Driver"
        FactoryName="pmaManoj" Name="pmaManojFactoryName"
        Password="{3DES}SUiVlz7r/rM=" Properties=""
        URL="jdbc:bea:db2://he1aixd1-1.fhlmc.com:60010" UserName="pmaenv1"/>

let me know is it stiill required to give the configuration in web.xml and  weblogic.xml file

manoj
0
petmagdyCommented:
ok please try as my last comment and tell me
0
ManojKBeheraAuthor Commented:
Hi,

I am getting the Exception the same...

javax.naming.NameNotFoundException: While trying to look up comp/env/jdbc/PMAMANOJ in /app/ejb/gridsvc.jar#pma/SellerSession.; remaining name 'comp/env/jdbc/PMA
MANOJ'
        at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(Basic
NamingNode.java:858)

I have followed all the above steps but anble to find the path for datasource.

Manoj
0
petmagdyCommented:
Ok then u r calling from EJb not Web?

 in this case move the descriptor from web.xml to ejb-jar.xml and from weblogic.xml to weblogic-ejb-jar.xml as following:

the session bean descriptor in ejb-jar.xml for SellerSession should look like this:

  <session>
      <display-name>SellerSession</display-name>
      <ejb-name>SellerSession</ejb-name>
      <home>......</home>
      <remote>.......</remote>
      <local-home>......</local-home>
      <local>.......</local>
      <ejb-class>...........</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <resource-ref>
        <res-ref-name>jdbc/PMAMANOJ</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>
    </session>


for weblogic-ejb-jar.xml will look like this:

<weblogic-ejb-jar>
  <weblogic-enterprise-bean>
    <ejb-name>SellerSession</ejb-name>

    <reference-descriptor>
      <resource-description>
        <res-ref-name>jdbc/PMAMANOJ</res-ref-name>
      <jndi-name>PMATDS</jndi-name>
      </resource-description>
    </reference-descriptor>

    <jndi-name>.............</jndi-name>

  </weblogic-enterprise-bean>

</weblogic-ejb-jar>


0
ManojKBeheraAuthor Commented:
In this case is is not specific to that session bean. generally the Datasource is specific to the application now Bean.

let me know your comment

Manoj
0
petmagdyCommented:
Manoj....

We r using local reference Lookup from its name is local, in case of u r getting datasource connection from a Web Code (Servlet/JSP container) the local refernces are defined in Web.xml, in case of EJB it is defined inside ejb-jar.xml on the single bean level. You must Isolate Local Reference Lookup from JNDI name lookup,
actually 10 different local references can be mapped to a single JNDI name for example, the mapping happens in the extension deployment descripter like weblogic-ejb.jar in weblogic and sun-ejb-jar.xml in Sun Application server

Please give it a try and tell me
0
ManojKBeheraAuthor Commented:
Yes its working fine for single session Bean.. Thanks a lot..

But we have more that 25 session bean in out project . To access the same "DataSource" Is it necessary to put  the same above configuration in all the session bean.

If we will going to put the same configuration then I think so we have look for other alternative.

Please let me know your comment  How to resolve  to  look up  more that 25 session bean to the  same DataSource.

waiting for your quick response...

thanks
manoj
0
petmagdyCommented:
Not to my knowledge and I don't think this is found, as it is assumed each bean may lookup to a different datasource, u will just copy and paste in each session bean
0
petmagdyCommented:
manoj, I also want to say that this is the standard way now in J2EE is to use local references to keep not married to the application Server specific JNDI implementation, if u notice the if the application server is changed the Code and the standard deployment descriptors will remain the same without change
0
petmagdyCommented:
Manoj..

How is doing? R u statisfied with my last comment
0
ManojKBeheraAuthor Commented:
Hi pet,

I am Good.. How r u??
I have one  doubt. can we do one thing instead of keeping the resource- ref in all the bean Can we put the configuration in one place so that we need to change all the session bean  cofiguration...

What do u say...becos since we have lot of ejb which connect  this database configuation so looking to use some commn place.

Its help us to main this connection easily.

Let me know your comment

Manoj
0
petmagdyCommented:
Manoj the Ejb components are designed to be independent components, because the are distributed component architecture, which means, each bean can be used in an Enterprise enviroment from more than on application of different type (Web, other EJB, Swing Client, C++ client and others) hence it should not be married to certain application, hence each Ejb Bean has its own local reference, also I reviewed the whole J2EE specifications and blueprints and found that is the right and standard way to do things, in all the J2EE applications i worked in this was the way used, their is no other place to define a resource references to be common for more than EJB s I told as the platform design is considering each bean is self dependent

petmagdy
0
ManojKBeheraAuthor Commented:
hey pet,

Suppose in the future the datasource name is going to change so we have to go to all the ejb and cahnge the datasource which interact with this datasource.

Suppose this application is in production its a tidious task..

what do u say..

manoj
 
0
petmagdyCommented:
noooooooooo, that is the beauty of it, u will only change the JNDI name in the Extension deployments (in weblogic-ejb-jar.xml) the Local References will still be the same not affected at alllllllllll :)
0
ManojKBeheraAuthor Commented:
Hi pet,

Still we have change all the Datasourec anme in each ejb rght.. mean if we have 10 ejb  then we have to change in 10 place. can it be possible so that we cahnge in one place so that it can refelect in all the place instaed of going to all the JNDI name in all ejb

manoj
0
petmagdyCommented:
what do mean when u say " in all ejb"? It is only in the Extension Deployment descriptor (extension means the Application Server Specific descriptors like weblogic-ejb-jar.xml) but the Code, the ejb-jar.xml, web.xml, else will never been untouched!!

Petmagdy
0
ManojKBeheraAuthor Commented:
I mean to say

<weblogic-enterprise-bean>
      <ejb-name>pma/SellerSession</ejb-name>
      <stateless-session-descriptor>
      </stateless-session-descriptor>
      <reference-descriptor>
         <resource-description>
            <res-ref-name>jdbc/PMAMANOJ</res-ref-name>
            <jndi-name>PMATDS</jndi-name>
         </resource-description>
      </reference-descriptor>
      <jndi-name>pma/SellerSession</jndi-name>
   </weblogic-enterprise-bean>

   <weblogic-enterprise-bean>
      <ejb-name>pma/GridFamilySession</ejb-name>
      <stateless-session-descriptor>
      </stateless-session-descriptor>
     <reference-descriptor>
         <resource-description>
            <res-ref-name>jdbc/PMAMANOJ</res-ref-name>
            <jndi-name>PMATDS</jndi-name>
         </resource-description>
      </reference-descriptor>

      <jndi-name>pma/GridFamilySession</jndi-name>
   </weblogic-enterprise-bean>


See the above code In both place we have to chnage JNDI name right .
Mean in future if we change the jNDi name we have to change both the JNDI name mapping in both the EJB mapping.. right...

I mean to say I want to change in one place globally intead of change both place.

Manoj

let me know your comment
0
petmagdyCommented:
yes u r right every <jndi-name> tag value will be replaced, no other way else, i reviewed the weblogic-ejb-jar.xml DTD this is the only place to define the reference - JNDIName mapping which is enside <weblogic-enterprise-bean> tag (each EJB) but as I say this is the Ideal design for the reasons I mentioned before

Petmagdy
0
ManojKBeheraAuthor Commented:
Context context1 = (Context)context.lookup("java:app/jdbc");
DataSource ds = (DataSource)context1.lookup(PMA_DATASOURCE_NAME);
con = ds.getConnection();

I got the resolution for that. instead of doing java:comp/env we can look up to java:app/jdbc because application scope connection pool context piont to java:app/jdbc not java:comp/env.

In this case we need to put ant thing in ejb-jar.xml or weblogic-ejb-jar.xml simple change in one place.

even the documantaion given wrong in e-docs.

Thanks
manoj
0
petmagdyCommented:
gooooodddddd excellent
0
ManojKBeheraAuthor Commented:
Hi pet,

do u know how to make twophasecommit is enable in Application scope connection pooling.

let me know yur comment

Thanks
Manoj
0
petmagdyCommented:
sorry Manoj this a complete new subject I prefer to post this as a new question and close this thread, also if u felt that I were helpful to you please award me with some points
the experts are working hard and investing time on this site to help people and to collect points for awards and certificates :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petmagdyCommented:
thanks Manoj, was pleasure to help u
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.