Solved

Unable to locate the DataSource in Application Scope Connection pooling

Posted on 2004-10-22
780 Views
Last Modified: 2013-12-10
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

0
Question by:ManojKBehera
    32 Comments
     
    LVL 8

    Expert Comment

    by:kiranhk
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    ok please try as my last comment and tell me
    0
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    Manoj..

    How is doing? R u statisfied with my last comment
    0
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    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
     

    Author Comment

    by:ManojKBehera
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    gooooodddddd excellent
    0
     

    Author Comment

    by:ManojKBehera
    Hi pet,

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

    let me know yur comment

    Thanks
    Manoj
    0
     
    LVL 13

    Accepted Solution

    by:
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    thanks Manoj, was pleasure to help u
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
    This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now