Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Unable to locate the DataSource in Application Scope Connection pooling

Posted on 2004-10-22
32
Medium Priority
?
817 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
Comment
Question by:ManojKBehera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 18
  • 13
32 Comments
 
LVL 8

Expert Comment

by:kiranhk
ID: 12385564
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
ID: 12385586
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
ID: 12386866
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ManojKBehera
ID: 12386883
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
ID: 12387653
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
ID: 12387857
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
ID: 12387942
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
ID: 12387967
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
ID: 12388019
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
ID: 12388439
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
ID: 12388642
ok please try as my last comment and tell me
0
 

Author Comment

by:ManojKBehera
ID: 12389189
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
ID: 12389293
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
ID: 12389355
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
ID: 12389391
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
ID: 12389910
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
ID: 12389954
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
ID: 12389972
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
ID: 12400908
Manoj..

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

Author Comment

by:ManojKBehera
ID: 12405311
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
ID: 12405785
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
ID: 12411274
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
ID: 12411746
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
ID: 12411996
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
ID: 12412204
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
ID: 12412355
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
ID: 12412585
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
ID: 12413856
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
ID: 12414704
gooooodddddd excellent
0
 

Author Comment

by:ManojKBehera
ID: 12423121
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:
petmagdy earned 1500 total points
ID: 12424150
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
ID: 12424359
thanks Manoj, was pleasure to help u
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
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 …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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