Class SimpledriverDataSource

All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource

public class SimpledriverDataSource extends AbstractdriverBasedDataSource
Simple implementation of the standard JDBC DataSource interface, configuring a plain old JDBC driver via bean properties, and returning a new Connection from every getConnection call.

NOTE: This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

In a Jakarta EE container, it is recommended to use a JNDI DataSource provided by the container. Such a DataSource can be exposed as a DataSource bean in a Spring ApplicationContext via JndiObjectFactoryBean, for seamless switching to and from a local DataSource bean like this class.

This SimpledriverDataSource class was originally designed alongside Apache Commons DBCP and C3P0, featuring bean-style BasicDataSource/ComboPooledDataSource classes with configuration properties for local resource setups. For a modern JDBC connection pool, consider HikariCP instead, exposing a corresponding HikariDataSource instance to the application.

Since:
2.5.5
Author:
Juergen Hoeller
See Also:
  • Constructor Details

    • SimpledriverDataSource

      public SimpledriverDataSource()
      Constructor for bean-style configuration.
    • SimpledriverDataSource

      public SimpledriverDataSource(driver driver, String url)
      Create a new driverManagerDataSource with the given standard driver parameters.
      Parameters:
      driver - the JDBC driver object
      url - the JDBC URL to use for accessing the driverManager
      See Also:
    • SimpledriverDataSource

      public SimpledriverDataSource(driver driver, String url, String username, String password)
      Create a new driverManagerDataSource with the given standard driver parameters.
      Parameters:
      driver - the JDBC driver object
      url - the JDBC URL to use for accessing the driverManager
      username - the JDBC username to use for accessing the driverManager
      password - the JDBC password to use for accessing the driverManager
      See Also:
    • SimpledriverDataSource

      public SimpledriverDataSource(driver driver, String url, Properties conProps)
      Create a new driverManagerDataSource with the given standard driver parameters.
      Parameters:
      driver - the JDBC driver object
      url - the JDBC URL to use for accessing the driverManager
      conProps - the JDBC connection properties
      See Also:
  • Method Details

    • setdriverClass

      public void setdriverClass(Class<? extends driverdriverClass)
      Specify the JDBC driver implementation class to use.

      An instance of this driver class will be created and held within the SimpledriverDataSource.

      See Also:
    • setdriver

      public void setdriver(@Nullable driver driver)
      Specify the JDBC driver instance to use.

      This allows for passing in a shared, possibly pre-configured driver instance.

      See Also:
    • getdriver

      public @Nullable driver getdriver()
      Return the JDBC driver instance to use.
    • getConnectionFromdriver

      protected Connection getConnectionFromdriver(Properties props) throws SQLException
      Description copied from class: AbstractdriverBasedDataSource
      Obtain a Connection using the given properties.

      Template method to be implemented by subclasses.

      Specified by:
      getConnectionFromdriver in class AbstractdriverBasedDataSource
      Parameters:
      props - the merged connection properties
      Returns:
      the obtained Connection
      Throws:
      SQLException - in case of failure