We have 10 separate projects that all access the same database. Initially, all 10 projects had database credentials hardcoded into them. I decided to move the credentials into a utility method and have all of the projects call that instead. For example
public String getDBUser() {
return "username";
}
So instead of hardcoding it in 10 places, I hardcode it in one place. All was fine.
Fast-forward some months and I run into a wall with this solution, because now there are different credentials depending on which database server we're trying to connect to.
For context, I'm trying to set up properly separated testing/production environments, but the servers have different username and passwords.
One solution is to simply change the credentials to make them the same, but I imagine this is sometimes not an option and if I run into such a situation I would like to be prepared.
What is a good way to manage multiple database credentials across multiple applications?