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??
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With