Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Externally specified environment

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sure this is a basic stupid question, so hopefully someone can give me a quick answer. I have an application which includes jsps, javabeans, and EJBs. At this moment all references to the database are coded directly in the files which they are used from. The problem is that I need to be able to change both the driver and the url/user/pass for the database without recompiling the code. Can someone *please* tell me the appropriate way to do this?
I can't just read in my own properties file (not supposed to read files directly with EJB), I can't use web.xml (servlet context not available in an EJB), I can't just specify it in the EJB descriptors (can't see them from the jsp), and I can't seem to figure out how to use the application resource files (*.properties) in order to access them via the InitialContext. I realize some of these things might sound completely inane, but I'm very new to java and still quite unfamiliar with some aspects of it.
My bottom line question is how can I configure a property (any property I make up) in a non-compiled file which I can somehow retrieve in a jsp, javabean, AND EJB. Thanks for any help.
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The official way to do anything like this in J2EE is to use JNDI. If you are using EJB you should already be familiar with JNDI lookups which you use to get your EJB interfaces. Simply put your database info into the JNDI context and you should be able to get at it from wherever you like. Ideally you should only need to read database connection information from some sort of connection pool, so also check if your Application server provides one which you can use.
 
Ben Roy
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is exactly where I'd gotten around to, but it doesn't seem to be working. I have 8 EJBs and 2 datasources in the same project. All of them (including the datasources) have JNDI names specified. When it's all running in the app server I can't look up the datasources. When I do ctx.lookup("MYBEAN") it returns a stub just fine but if I do ctx.lookup("MYDATASOURCE") it doesn't work. Nor does any variation that I have tried like ctx.lookup("jdbc/MYDATASOURCE") or something. I've seen many different things to search for in books, etc, but I haven't been able to look it up under any method. This is on IAS 4.1. Anyone have any thoughts?
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic