src/java.sql/share/classes/java/sql/Driver.java
changeset 47216 71c04702a3d5
parent 44256 12050b22e372
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package java.sql;
       
    27 
       
    28 import java.util.logging.Logger;
       
    29 
       
    30 /**
       
    31  * The interface that every driver class must implement.
       
    32  * <P>The Java SQL framework allows for multiple database drivers.
       
    33  *
       
    34  * <P>Each driver should supply a class that implements
       
    35  * the Driver interface.
       
    36  *
       
    37  * <P>The DriverManager will try to load as many drivers as it can
       
    38  * find and then for any given connection request, it will ask each
       
    39  * driver in turn to try to connect to the target URL.
       
    40  *
       
    41  * <P>It is strongly recommended that each Driver class should be
       
    42  * small and standalone so that the Driver class can be loaded and
       
    43  * queried without bringing in vast quantities of supporting code.
       
    44  *
       
    45  * <P>When a Driver class is loaded, it should create an instance of
       
    46  * itself and register it with the DriverManager. This means that a
       
    47  * user can load and register a driver by calling:
       
    48  * <p>
       
    49  * {@code Class.forName("foo.bah.Driver")}
       
    50  * <p>
       
    51  * A JDBC driver may create a {@linkplain DriverAction} implementation in order
       
    52  * to receive notifications when {@linkplain DriverManager#deregisterDriver} has
       
    53  * been called.
       
    54  * @see DriverManager
       
    55  * @see Connection
       
    56  * @see DriverAction
       
    57  * @since 1.1
       
    58  */
       
    59 public interface Driver {
       
    60 
       
    61     /**
       
    62      * Attempts to make a database connection to the given URL.
       
    63      * The driver should return "null" if it realizes it is the wrong kind
       
    64      * of driver to connect to the given URL.  This will be common, as when
       
    65      * the JDBC driver manager is asked to connect to a given URL it passes
       
    66      * the URL to each loaded driver in turn.
       
    67      *
       
    68      * <P>The driver should throw an <code>SQLException</code> if it is the right
       
    69      * driver to connect to the given URL but has trouble connecting to
       
    70      * the database.
       
    71      *
       
    72      * <P>The {@code Properties} argument can be used to pass
       
    73      * arbitrary string tag/value pairs as connection arguments.
       
    74      * Normally at least "user" and "password" properties should be
       
    75      * included in the {@code Properties} object.
       
    76      * <p>
       
    77      * <B>Note:</B> If a property is specified as part of the {@code url} and
       
    78      * is also specified in the {@code Properties} object, it is
       
    79      * implementation-defined as to which value will take precedence. For
       
    80      * maximum portability, an application should only specify a property once.
       
    81      *
       
    82      * @param url the URL of the database to which to connect
       
    83      * @param info a list of arbitrary string tag/value pairs as
       
    84      * connection arguments. Normally at least a "user" and
       
    85      * "password" property should be included.
       
    86      * @return a <code>Connection</code> object that represents a
       
    87      *         connection to the URL
       
    88      * @exception SQLException if a database access error occurs or the url is
       
    89      * {@code null}
       
    90      */
       
    91     Connection connect(String url, java.util.Properties info)
       
    92         throws SQLException;
       
    93 
       
    94     /**
       
    95      * Retrieves whether the driver thinks that it can open a connection
       
    96      * to the given URL.  Typically drivers will return <code>true</code> if they
       
    97      * understand the sub-protocol specified in the URL and <code>false</code> if
       
    98      * they do not.
       
    99      *
       
   100      * @param url the URL of the database
       
   101      * @return <code>true</code> if this driver understands the given URL;
       
   102      *         <code>false</code> otherwise
       
   103      * @exception SQLException if a database access error occurs or the url is
       
   104      * {@code null}
       
   105      */
       
   106     boolean acceptsURL(String url) throws SQLException;
       
   107 
       
   108 
       
   109     /**
       
   110      * Gets information about the possible properties for this driver.
       
   111      * <P>
       
   112      * The <code>getPropertyInfo</code> method is intended to allow a generic
       
   113      * GUI tool to discover what properties it should prompt
       
   114      * a human for in order to get
       
   115      * enough information to connect to a database.  Note that depending on
       
   116      * the values the human has supplied so far, additional values may become
       
   117      * necessary, so it may be necessary to iterate though several calls
       
   118      * to the <code>getPropertyInfo</code> method.
       
   119      *
       
   120      * @param url the URL of the database to which to connect
       
   121      * @param info a proposed list of tag/value pairs that will be sent on
       
   122      *          connect open
       
   123      * @return an array of <code>DriverPropertyInfo</code> objects describing
       
   124      *          possible properties.  This array may be an empty array if
       
   125      *          no properties are required.
       
   126      * @exception SQLException if a database access error occurs
       
   127      */
       
   128     DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)
       
   129                          throws SQLException;
       
   130 
       
   131 
       
   132     /**
       
   133      * Retrieves the driver's major version number. Initially this should be 1.
       
   134      *
       
   135      * @return this driver's major version number
       
   136      */
       
   137     int getMajorVersion();
       
   138 
       
   139     /**
       
   140      * Gets the driver's minor version number. Initially this should be 0.
       
   141      * @return this driver's minor version number
       
   142      */
       
   143     int getMinorVersion();
       
   144 
       
   145 
       
   146     /**
       
   147      * Reports whether this driver is a genuine JDBC
       
   148      * Compliant&trade; driver.
       
   149      * A driver may only report <code>true</code> here if it passes the JDBC
       
   150      * compliance tests; otherwise it is required to return <code>false</code>.
       
   151      * <P>
       
   152      * JDBC compliance requires full support for the JDBC API and full support
       
   153      * for SQL 92 Entry Level.  It is expected that JDBC compliant drivers will
       
   154      * be available for all the major commercial databases.
       
   155      * <P>
       
   156      * This method is not intended to encourage the development of non-JDBC
       
   157      * compliant drivers, but is a recognition of the fact that some vendors
       
   158      * are interested in using the JDBC API and framework for lightweight
       
   159      * databases that do not support full database functionality, or for
       
   160      * special databases such as document information retrieval where a SQL
       
   161      * implementation may not be feasible.
       
   162      * @return <code>true</code> if this driver is JDBC Compliant; <code>false</code>
       
   163      *         otherwise
       
   164      */
       
   165     boolean jdbcCompliant();
       
   166 
       
   167     //------------------------- JDBC 4.1 -----------------------------------
       
   168 
       
   169     /**
       
   170      * Return the parent Logger of all the Loggers used by this driver. This
       
   171      * should be the Logger farthest from the root Logger that is
       
   172      * still an ancestor of all of the Loggers used by this driver. Configuring
       
   173      * this Logger will affect all of the log messages generated by the driver.
       
   174      * In the worst case, this may be the root Logger.
       
   175      *
       
   176      * @return the parent Logger for this driver
       
   177      * @throws SQLFeatureNotSupportedException if the driver does not use
       
   178      * {@code java.util.logging}.
       
   179      * @since 1.7
       
   180      */
       
   181     public Logger getParentLogger() throws SQLFeatureNotSupportedException;
       
   182 }