File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Obtaining User/Password info for DB connections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Obtaining User/Password info for DB connections" Watch "Obtaining User/Password info for DB connections" New topic

Obtaining User/Password info for DB connections

Travis Gibson
Ranch Hand

Joined: Oct 17, 2000
Posts: 100
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?

Travis M. Gibson, SCJP
Java Developer

Regards,<BR>Travis M. Gibson, SCJP<BR>Java Developer<BR><BR>
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
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.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
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 :
maha anna

[This message has been edited by maha anna (edited April 20, 2001).]
I agree. Here's the link:
subject: Obtaining User/Password info for DB connections
It's not a secret anymore!