This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes reading properties to get connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reading properties to get connection" Watch "reading properties to get connection" New topic
Author

reading properties to get connection

raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
hi,
i want to store username and password in a properties file and get these
values in a bean class which is having a method to get the connection.
eg
[ public class App{
public Connection getConnection(){
String user= //from properties file
String password= // from properties file
......

}
}
can you tell me the ways to achieve this.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42367
    
  64
You could either use the Properties.load method to read the file, or use a PropertyResourceBundle.


Ping & DNS - my free Android networking tools app
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...
[ November 30, 2006: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Isn't a properties file just plain text, like an .ini file? If a password were stored as a property, couldn't someone just open the properties file and see all of the passwords?

-- Kaydell
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42367
    
  64
The assumption is that either this is a client app (in which case all of the client hard disk is fair game) or this is a server app (in which case none of the clents can access it). Maybe the original poster will tell us which one it is.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: reading properties to get connection