0

Is it possible to connect to a MySQL database without specifying the username and password in Java code:

Connection con=DriverManager.getConnection("database url","username","password");

I want to be able to have my password in a private spot and call that password somehow in a safe manner. Any tips for this?

Madhu Sharma
  • 562
  • 4
  • 9

1 Answers1

0

I suggest you to make a config file. You can do it with librairies like Yaml (or Hocon for .conf files, ...):

YamlConfiguration.loadConfiguration(configFile);

Then get username, password (and even database URL) :

yamlConfig.getString("database.username"); // can be null if not registered in file
Elikill58
  • 4,050
  • 24
  • 23
  • 45