Package org.dbunit

Class JdbcDatabaseTester

All Implemented Interfaces:
IDatabaseTester
Direct Known Subclasses:
PropertiesBasedJdbcDatabaseTester

public class JdbcDatabaseTester extends AbstractDatabaseTester
DatabaseTester that uses JDBC's Driver Manager to create connections.
Since:
2.2
Version:
$Revision$
Author:
Andres Almiray (aalmiray@users.sourceforge.net), Felipe Leme (dbunit@felipeal.net)
  • Constructor Details

    • JdbcDatabaseTester

      public JdbcDatabaseTester(String driverClass, String connectionUrl) throws ClassNotFoundException
      Creates a new JdbcDatabaseTester with the specified properties.
      Username and Password are set to null.
      Parameters:
      driverClass - the classname of the JDBC driver to use
      connectionUrl - the connection url
      Throws:
      ClassNotFoundException - If the given driverClass was not found
    • JdbcDatabaseTester

      public JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password) throws ClassNotFoundException
      Creates a new JdbcDatabaseTester with the specified properties.
      Parameters:
      driverClass - the classname of the JDBC driver to use
      connectionUrl - the connection url
      username - a username that can has access to the database
      password - the user's password
      Throws:
      ClassNotFoundException - If the given driverClass was not found
    • JdbcDatabaseTester

      public JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password, String schema) throws ClassNotFoundException
      Creates a new JdbcDatabaseTester with the specified properties.
      Parameters:
      driverClass - the classname of the JDBC driver to use
      connectionUrl - the connection url
      username - a username that can has access to the database - can be null
      password - the user's password - can be null
      schema - the database schema to be tested - can be null
      Throws:
      ClassNotFoundException - If the given driverClass was not found
      Since:
      2.4.3
    • JdbcDatabaseTester

      public JdbcDatabaseTester(String driverClass, String connectionUrl, String username, String password, String schema, CachingConnectionProvider connectionProvider) throws ClassNotFoundException
      Creates a new JdbcDatabaseTester with the specified properties, reusing one IDatabaseConnection across calls via the given CachingConnectionProvider instead of creating a new one on every call.
      Share the same connectionProvider instance across the testers created for each test to get reuse across test methods; pair it with IOperationListener.NO_OP_OPERATION_LISTENER (or an equivalent non-closing listener) so the cached connection is not closed after every AbstractDatabaseTester.onSetup()/AbstractDatabaseTester.onTearDown() call.
      Parameters:
      driverClass - the classname of the JDBC driver to use
      connectionUrl - the connection url
      username - a username that can has access to the database - can be null
      password - the user's password - can be null
      schema - the database schema to be tested - can be null
      connectionProvider - caches and validates the connection across calls - can be null, in which case a new connection is created on every call as before
      Throws:
      ClassNotFoundException - If the given driverClass was not found
      Since:
      3.4.0
  • Method Details

    • isReusingConnection

      public boolean isReusingConnection()
      Returns whether getConnection() hands out one connection, cached by the CachingConnectionProvider this tester was built with, instead of creating a new connection on every call. A caller that leaves a connection open for its owner to close can rely on a tester that reuses its connection; with one that creates a new connection on every call, nothing closes the connection left open.

      A subclass that overrides getConnection() to reuse a connection overrides this method to say so.

      Returns:
      true when this tester was built with a CachingConnectionProvider.
      Since:
      3.6.0
    • getConnection

      public IDatabaseConnection getConnection() throws Exception
      Description copied from interface: IDatabaseTester
      Returns the test database connection.
      Returns:
      the test database connection.
      Throws:
      Exception - if the connection cannot be retrieved or created.
    • toString

      public String toString()
      Overrides:
      toString in class AbstractDatabaseTester