Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
kishukishor patil
Greenhorn
Posts: 23
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an<env-entry> in the ejb-jar.xml....
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic