02: JDBC with MySQL, Datasource, and connection pool Tutorial

Step 1: pom.xml file with commons-dbcp2 for the connection pooling and abstraction layer for the datasource.

db.properties for connection details

Step 2: Create a new source folder “src/main/resources”.

Step 3: Define the MySQL database “learnjavadb” connection properties in a new file named “db.properties” under “src/main/resources”.

Using the “MysqlDataSource”

Step 4: Modify the “ConnectionUtil.java” to use “MysqlDataSource” & “db.properties” to get a database connection.

A generic Datasource with a connection pool

Step 5: Revised “ConnectionUtil.java” using commons-dbcp2’s “BasicDataSource”.


Java Developer Interview Q&As

800+ Java Interview Q&As

Top