Package org.apache.commons.dbcp2

# Class DataSourceConnectionFactory

java.lang.Object
org.apache.commons.dbcp2.DataSourceConnectionFactory

All Implemented Interfaces:
  `ConnectionFactory`

public class DataSourceConnectionFactory extends Object implements ConnectionFactory
A `DataSource`-based implementation of `ConnectionFactory`.

Since:
  2.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DataSourceConnectionFactory(DataSource dataSource)`
  Constructs an instance for the given DataSource.
  `DataSourceConnectionFactory(DataSource dataSource, String userName, char[] userPassword)`
  Constructs an instance for the given DataSource.
  `DataSourceConnectionFactory(DataSource dataSource, String userName, String password)`
  Constructs an instance for the given DataSource.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Connection`
  `createConnection()`
  Create a new `Connection` in an implementation specific fashion.
  `DataSource`
  `getDataSource()`
  `String`
  `getUserName()`
  `char[]`
  `getUserPassword()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DataSourceConnectionFactory

    public DataSourceConnectionFactory(DataSource dataSource)
    Constructs an instance for the given DataSource.
    Parameters:
      `dataSource` - The DataSource for this factory.

  - ### DataSourceConnectionFactory

    public DataSourceConnectionFactory(DataSource dataSource, String userName, char[] userPassword)
    Constructs an instance for the given DataSource.
    Parameters:
      `dataSource` - The DataSource for this factory.
      `userName` - The user name.
      `userPassword` - The user password.
    Since:
      2.4.0

  - ### DataSourceConnectionFactory

    public DataSourceConnectionFactory(DataSource dataSource, String userName, String password)
    Constructs an instance for the given DataSource.
    Parameters:
      `dataSource` - The DataSource for this factory.
      `userName` - The user name.
      `password` - The user password.

- ## Method Details

  - ### createConnection

    public Connection createConnection() throws SQLException
    Description copied from interface: `ConnectionFactory`
    Create a new `Connection` in an implementation specific fashion.
    Specified by:
      `createConnection` in interface `ConnectionFactory`
    Returns:
      a new `Connection`
    Throws:
      `SQLException` - if a database error occurs creating the connection

  - ### getDataSource

    public DataSource getDataSource()
    Returns:
      The data source.
    Since:
      2.6.0

  - ### getUserName

    public String getUserName()
    Returns:
      The user name.
    Since:
      2.6.0

  - ### getUserPassword

    public char[] getUserPassword()
    Returns:
      The user password.
    Since:
      2.6.0