JDBC database connection using property resource(property file)

By | July 15, 2018

In previous post JDBC MySQL database Connection example we learnt how to connect java program with database using various approaches.

In this post we will learn how to segregate database information like database URL,username,password etc. from source code and keeping in .properties file.

Project structure in eclipse:

Property file(database.properties) which holds database information like database URL,username and password.

DBUtil.java class which is responsible to connect with MySQL database.

Here You would have observed that how database.properties file is loaded using load method of java.util.Properties class.
After that we get every property value from properties file by using getProperty(String key) method

ClientTest.java client class which makes use of DBUtil to take connection from database(MySQL).

When you run ClientTest .java in your favorite IDE then you will get below out.

This shows  we successfully connected our java program with MYSQL database.

That’s all about  this topic JDBC database connection using property resource(property file)
If you have any feedback or suggestion please feel free to drop in blow comment box. 

Leave a Reply

Your email address will not be published. Required fields are marked *