It also abstracts away database connection related plumbing, and allows developers to focus on business logic.
Use of JDBC API allows for flexibility of changing data source implementation driver form MySQL to Oracle for example, and allows using improved data source specific connection pool implementations. It has many benefits one of which is increased performance and reduced connection creation and removal overhead due to connection reuse by the connection pool. Connection pooling has many benefits and is part of the Java EE standard implemented by Tomcat. The connection to the data source, such as database is attempted when ‘s getConnection() method is called. A DataSource object is looked up in the context based on registered through JNDI Resource. A data source driver allows accessed to the database via DataSource interface.
interface is registered with the naming service based on JNDI API. is a factory for getting connections to different physical data sources. In this example we will discuss setting a global DataSource for MySQL database. The connection pool we will look at is, which is a JDBC API for getting a connection instance to a database.
In this example we will discuss Apache Tomcat Servlet/JSP container’s connection pull configuration via JNDI (Java Naming and Directory Interface ) resources.