The first step to connect to a database from any Java application is to obtain a connection object specified by JDBC. DataSource
, a part of Java SE, is a generalized factory of java.sql.Connection
objects that represents the physical connection to the database and is the preferred means of producing a connection. DataSource
handles transaction management, connection lookup, and pooling functionalities, relieving the developer of those infrastructural issues.
DataSource
objects are often implemented by database driver vendors and typically looked up via JNDI. Application servers and Servlet engines provide their own implementations of DataSource
(and) or connectors to DataSource
objects provided by the database vendor. Typically configured inside XML-based server descriptor files, server-supplied DataSource
objects generally provide built-in connection pooling and transaction support. As a developer, you just configure your data sources inside the server configuration...