Product Documentation

FairCom JDBC Developer's Guide

Previous Topic

Next Topic

Using A DataSource Object To Make A Connection

The <FairCom DB SQL JDBC javax.sql package provides the preferred way to make a connection with a data source. The DriverManager class, the original mechanism, is still valid, and code using it will continue to run. However, the newer DataSource mechanism is preferred because it offers many advantages over the DriverManager mechanism.

The following are the main advantages of using a DataSource object to make a connection:

  • Applications do not need to hard code a driver class.
  • Changes can be made to a data source’s properties, which means that it is not necessary to make changes in application code when something about the data source or driver changes.
  • Connection pooling and distributed transactions are available through a DataSource object that is implemented to work with the middle-tier infrastructure. Connections made through the DriverManager do not have connection pooling or distributed transaction capabilities.

A particular DataSource object represents a particular physical data source, and each connection the DataSource object creates is a connection to that physical data source. A DataSource object can be implemented to work with the middle tier infrastructure so that the connections it produces will be pooled for reuse. An application that uses such a DataSource implementation will automatically get a connection that participates in connection pooling. A DataSource object can also be implemented to work with the middle tier infrastructure so that the connections it produces can be used for distributed transactions without any special coding.

TOCIndex