MysqlDataSource example

By | August 5, 2018

In this post we will learn about MysqlDataSource using an example

Project structure in eclipse:

Create database.properties file in src folder as shown in the above project structure and make entry of below properties.

SQL Query to create employee_table in MySQL (jdbcpooldb schema)

Once you execute above db script your database schema(jdbcpooldb) will be created and employee_table will be created with three rows as below.

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

ClientTest.java class which makes use of DBUtil.getDataSource()  method to take connection from MysqlDataSource .

After running ClientTest.java program you will look below  output on eclipse console:  

Above eclipse console output shows we are able to read rows from MySQL database that means we are successfully taken database connection using MysqlDataSource

That’s all about  this topic MysqlDataSource example.
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 *