Class DriverManager


  • public abstract class DriverManager
    extends Object
    The java.sql.DriverManager uses a native method to retrieve the classloader from the calling class which keeps the calling class (including its classloader) from being garbage collected. Therefore all accesses to the driver manager have to be encapsulated by a shared class (this class). Additionally, all JDBC-drivers have to be provided to the system classloader (and not to the component classloaders).
    Author:
    Ulrich Kreher
    See Also:
    DriverManager
    • Constructor Detail

      • DriverManager

        protected DriverManager()
        package protected constructor -> we provide the only implementation
    • Method Detail

      • loadDriver

        public abstract void loadDriver​(String className)
                                 throws DriverNotFoundException
        Gets the class with the designated name. This method has to be used instead of the usual Class.forName(className) to enforce the initialisation of the corresponding driver class.
        Parameters:
        className - The name of the class providing the JDBC-driver which should be registered.
        Throws:
        DriverNotFoundException - If the driver could not be loaded. Examine cause for more information.
      • getConnection

        public abstract Connection getConnection​(String url,
                                                 Properties info)
                                          throws SQLException
        Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
        Parameters:
        url - a database url of the form jdbc:subprotocol:subname
        info - a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and "password" property should be included
        Returns:
        a Connection to the URL
        Throws:
        SQLException - if a database access error occurs
      • getConnection

        public abstract Connection getConnection​(String url,
                                                 String user,
                                                 String password)
                                          throws SQLException
        Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
        Parameters:
        url - a database url of the form jdbc:subprotocol:subname
        user - the database user on whose behalf the connection is being made
        password - the user's password
        Returns:
        a connection to the URL
        Throws:
        SQLException - if a database access error occurs
      • getConnection

        public abstract Connection getConnection​(String url)
                                          throws SQLException
        Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
        Parameters:
        url - a database url of the form jdbc:subprotocol:subname
        Returns:
        a connection to the URL
        Throws:
        SQLException - if a database access error occurs
      • getDriver

        public abstract Driver getDriver​(String url)
                                  throws SQLException
        Attempts to locate a driver that understands the given URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
        Parameters:
        url - a database URL of the form jdbc:subprotocol:subname
        Returns:
        a Driver object representing a driver that can connect to the given URL
        Throws:
        SQLException - if a database access error occurs
      • getDrivers

        public abstract Enumeration<Driver> getDrivers()
        Retrieves an Enumeration with all of the currently loaded JDBC drivers to which the current caller has access.

        Note: The classname of a driver can be found using d.getClass().getName()

        Returns:
        the list of JDBC Drivers loaded by the caller's class loader
      • getLoginTimeout

        public abstract int getLoginTimeout()
        Gets the maximum time in seconds that a driver can wait when attempting to log in to a database.
        Returns:
        the driver login time limit in seconds
      • getInstance

        public static DriverManager getInstance​(String libDir)
        Returns the instance of the JDBC driver manager for the designated directory.
        Parameters:
        libDir - The library directory containing the JDBC drivers (actually the directory above a directory 'jdbc4' containing the JDBC drivers).
        Returns:
        The singleton instance of the JDBC driver manager