Path: blob/master/src/java.sql/share/classes/java/sql/Driver.java
41153 views
/*1* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627import java.util.logging.Logger;2829/**30* The interface that every driver class must implement.31* <P>The Java SQL framework allows for multiple database drivers.32*33* <P>Each driver should supply a class that implements34* the Driver interface.35*36* <P>The DriverManager will try to load as many drivers as it can37* find and then for any given connection request, it will ask each38* driver in turn to try to connect to the target URL.39*40* <P>It is strongly recommended that each Driver class should be41* small and standalone so that the Driver class can be loaded and42* queried without bringing in vast quantities of supporting code.43*44* <P>When a Driver class is loaded, it should create an instance of45* itself and register it with the DriverManager. This means that a46* user can load and register a driver by calling:47* <p>48* {@code Class.forName("foo.bah.Driver")}49* <p>50* A JDBC driver may create a {@linkplain DriverAction} implementation in order51* to receive notifications when {@linkplain DriverManager#deregisterDriver} has52* been called.53* @see DriverManager54* @see Connection55* @see DriverAction56* @since 1.157*/58public interface Driver {5960/**61* Attempts to make a database connection to the given URL.62* The driver should return "null" if it realizes it is the wrong kind63* of driver to connect to the given URL. This will be common, as when64* the JDBC driver manager is asked to connect to a given URL it passes65* the URL to each loaded driver in turn.66*67* <P>The driver should throw an {@code SQLException} if it is the right68* driver to connect to the given URL but has trouble connecting to69* the database.70*71* <P>The {@code Properties} argument can be used to pass72* arbitrary string tag/value pairs as connection arguments.73* Normally at least "user" and "password" properties should be74* included in the {@code Properties} object.75* <p>76* <B>Note:</B> If a property is specified as part of the {@code url} and77* is also specified in the {@code Properties} object, it is78* implementation-defined as to which value will take precedence. For79* maximum portability, an application should only specify a property once.80*81* @param url the URL of the database to which to connect82* @param info a list of arbitrary string tag/value pairs as83* connection arguments. Normally at least a "user" and84* "password" property should be included.85* @return a {@code Connection} object that represents a86* connection to the URL87* @throws SQLException if a database access error occurs or the url is88* {@code null}89*/90Connection connect(String url, java.util.Properties info)91throws SQLException;9293/**94* Retrieves whether the driver thinks that it can open a connection95* to the given URL. Typically drivers will return {@code true} if they96* understand the sub-protocol specified in the URL and {@code false} if97* they do not.98*99* @param url the URL of the database100* @return {@code true} if this driver understands the given URL;101* {@code false} otherwise102* @throws SQLException if a database access error occurs or the url is103* {@code null}104*/105boolean acceptsURL(String url) throws SQLException;106107108/**109* Gets information about the possible properties for this driver.110* <P>111* The {@code getPropertyInfo} method is intended to allow a generic112* GUI tool to discover what properties it should prompt113* a human for in order to get114* enough information to connect to a database. Note that depending on115* the values the human has supplied so far, additional values may become116* necessary, so it may be necessary to iterate though several calls117* to the {@code getPropertyInfo} method.118*119* @param url the URL of the database to which to connect120* @param info a proposed list of tag/value pairs that will be sent on121* connect open122* @return an array of {@code DriverPropertyInfo} objects describing123* possible properties. This array may be an empty array if124* no properties are required.125* @throws SQLException if a database access error occurs126*/127DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)128throws SQLException;129130131/**132* Retrieves the driver's major version number. Initially this should be 1.133*134* @return this driver's major version number135*/136int getMajorVersion();137138/**139* Gets the driver's minor version number. Initially this should be 0.140* @return this driver's minor version number141*/142int getMinorVersion();143144145/**146* Reports whether this driver is a genuine JDBC147* Compliant driver.148* A driver may only report {@code true} here if it passes the JDBC149* compliance tests; otherwise it is required to return {@code false}.150* <P>151* JDBC compliance requires full support for the JDBC API and full support152* for SQL 92 Entry Level. It is expected that JDBC compliant drivers will153* be available for all the major commercial databases.154* <P>155* This method is not intended to encourage the development of non-JDBC156* compliant drivers, but is a recognition of the fact that some vendors157* are interested in using the JDBC API and framework for lightweight158* databases that do not support full database functionality, or for159* special databases such as document information retrieval where a SQL160* implementation may not be feasible.161* @return {@code true} if this driver is JDBC Compliant; {@code false}162* otherwise163*/164boolean jdbcCompliant();165166//------------------------- JDBC 4.1 -----------------------------------167168/**169* Return the parent Logger of all the Loggers used by this driver. This170* should be the Logger farthest from the root Logger that is171* still an ancestor of all of the Loggers used by this driver. Configuring172* this Logger will affect all of the log messages generated by the driver.173* In the worst case, this may be the root Logger.174*175* @return the parent Logger for this driver176* @throws SQLFeatureNotSupportedException if the driver does not use177* {@code java.util.logging}.178* @since 1.7179*/180public Logger getParentLogger() throws SQLFeatureNotSupportedException;181}182183184