Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of Property file

I am creating properties file for database connection..I have given the path of the file and I am storing properties using the function:

 public void setProperty(String key, String value) {
    properties.setProperty(key, value);
}

I have set the properties like:

"url","jdbc:mysql://localhost:3306/";"dbname","example";"user", "postgres";"Pass","123";

My question is when I am using my application in another system how could this properties file is useful (Actually I have gone through the "property file in java" tutorials but I was unable to understand how they are used).

In new system user name and password would be different,so how could this file be useful??

like image 774
user10101 Avatar asked Mar 26 '12 12:03

user10101


1 Answers

In new system user name and password would be different,so how could this file be useful??

It is useful precisely because the file can be different on different systems. By putting the system-specific details into a file that can be changed on different systems, you avoid having to write different Java code for each different system.

But how could I know the other users user name and password

In the scenario where you don't know, you have a number of alternatives, such as:

  • telling the user to edit the properties file with a text editor,
  • coding your application's installer to ask the for the username and password and then insert them into the properties file at install time, or
  • providing a configuration tool or interface that allows the user to enter or update the properties.

By the way, it looks like you have invented a custom property file format. You didn't need to do that. The java.util.Properties class offers two standard formats and methods for reading and writing them.

like image 166
Stephen C Avatar answered Sep 27 '22 22:09

Stephen C