0

I am working on the Java desktop application using Swing. As the application is data centric, I am using the JDBC for connection with mySql. I would like to store database connection (connectionString), username and password in the seperate file. What will be the best approach for this?

(In .net app.config store these informations)

Nav Ali
  • 1,232
  • 6
  • 17
  • 26

2 Answers2

2

You can store the parameters in a properties file like

hostname=localhost:3306/mydb
username=root
password=pass


Store this information in a properties file like say config.properties. You can load the properties in java during runtime using the Properties class in java

Properties prop = new Properties();
prop.load(new FileInputStream("config.properties"));
String connectionString = prop.getProperty("hostname")
String username = prop.getProperty("username")
String password = prop.getProperty("password")
Rakesh
  • 4,264
  • 4
  • 32
  • 58
1

You can use a properties file for that. Hibernate has already its properties configuration file. You can also use hibernate.cfg.xml.

Stephan
  • 4,395
  • 3
  • 26
  • 49