This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
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

Which solution is the cleanest way to obtain user and password???

 
Travis Gibson
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fellow ranchers,
I am trying to decide which way is cleaner(I.e. easier to maintain and less error prone) for obtaining User and Password values for create a database connections.
1.) Use ServletInitParameters(web.xml or default_app.webapp(I use Websphere) to store the User/Pass values....Thanks Mana Anna
2.) Use a db.properties file to store the User/Pass and use a Properties object to obtain User/Pass
Both have their drawbacks. I can only use the ServletInitParameters for Servlets(JSP). For Properties file I have the properties file in my classpath.
I am leaning towards the properties file approach. I'd appreciate any comments however.

------------------
Regards,
Travis M. Gibson, SCJP
Java Developer
www.travismgibson.com
travis@travismgibson.com
 
Bhupinder Dhillon
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would go with properties file simply b/c you can write comments in it so that it's self explanatory and you don't have to keep track of init parameters in the server configuration files.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also comment the deployment descriptors
The cleanest way of all is to use the database provider from the application server through JNDI (if the appserver supports this, of course).
Something like:

That way the servlet does not need to bother with database connections at all and will use connection pooling automatically if provided by the appserver.
[This message has been edited by Jeroen Wenting (edited April 23, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic