This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Obtaining User/Password info for DB connections

 
Travis Gibson
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Fellow ranchers,
I have a question for you all. I am would like to create a connection to a database without having to hardcode the user/pass in the connection code or having to read a properties files to obtain it.
Any there any other ways that I could do this so that the code is clean, the user/pass can be changed without impacting connection code and without having to keep track of a properties file?

------------------
Regards,
Travis M. Gibson, SCJP
Java Developer
www.travismgibson.com
travis@travismgibson.com
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using servlets, you can have the user and password as part of the initial parameters and then just get them with ServletConfig.
Or you can have your basic get and set methods so your other classes and set the username and password with them. Also a constructor to set them would work.
Bill
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit ....\WEB-INF\web.xml file and include your init params. If you change those params in web.xml file after loading your servet engine, the new changes will not come into effect. One time init only.
A related discussion :
http://www.javaranch.com/ubb/Forum7/HTML/001790.html
regds
maha anna

[This message has been edited by maha anna (edited April 20, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic