aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes I need to store and use variable in EJB 2.0 like Application level variable in Servlets/Jsps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "I need to store and use variable in EJB 2.0 like Application level variable in Servlets/Jsps" Watch "I need to store and use variable in EJB 2.0 like Application level variable in Servlets/Jsps" New topic
Author

I need to store and use variable in EJB 2.0 like Application level variable in Servlets/Jsps

kishukishor patil
Greenhorn

Joined: Nov 20, 2008
Posts: 23

Hi,

I am using EJB 2.0 and i want to use variable like global variable, as we use application level or context level variables in Servles/jsp's like that i want to use variable in EJB 2.0. Please suggest is there any configuration in ejb's .xml file for this requirement.

Thanks
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Why do you want this? People usually say that global variable is not a good approach.

I think you can create a static variable in your bean or in any class. Like:

public class YourBean {

public static int myGlobalVariable;
}

Then you would use YourBean.myGlobalVariable;
kishukishor patil
Greenhorn

Joined: Nov 20, 2008
Posts: 23

Actually i want to configure Connection Pool Name. And if i configure it as you suggest then it will need code changes if my connection pool change. On the other hand if i configure it in any .xml file like context parameter then i can change it any time only need to restart the server. This is the main reason, Please suggest me any good option. Or if there is way to use connection pool with ejb.


Thanks brother...
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Use an<env-entry> in the ejb-jar.xml....


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

kishukishor patil wrote:Actually i want to configure Connection Pool Name. And if i configure it as you suggest then it will need code changes if my connection pool change. On the other hand if i configure it in any .xml file like context parameter then i can change it any time only need to restart the server. This is the main reason, Please suggest me any good option. Or if there is way to use connection pool with ejb.


Thanks brother...

Almost always you access a connection pool thru a datasource via jndi lookup. The datasource jndi name is specified in EJB XML files.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I need to store and use variable in EJB 2.0 like Application level variable in Servlets/Jsps