Saturday, November 11, 2017

Spring JDBC - Connect Spring application to database using JNDI (Mysql)

JNDI now a day is very popular as it provide the underline database connectivity directly to the application which providing any driver and connection string and all , everything has to be defined at application server level only the JNDI name is what matters to the spring application , it basically connect with database only by using the JNDI Name .

So how to connect with database using jndi

In this program we are trying to connect our spring application with Mysql database using Mysql JNDI which we are defining in tomcat server of the application.

Below is the tag we need to add in the tomcat context.xml.

<Resource name="jdbc/springlearning" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="root" password="root" driverClassName="com.mysql.jdbc.Driver"

below is the program

The structure of the project will be like below

Hope this will help you in understanding the program

Thanks for the reading


Post a Comment