Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/sql/Driver.java
38829 views
/*1* Copyright (c) 1996, 2013, 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*/57public interface Driver {5859/**60* Attempts to make a database connection to the given URL.61* The driver should return "null" if it realizes it is the wrong kind62* of driver to connect to the given URL. This will be common, as when63* the JDBC driver manager is asked to connect to a given URL it passes64* the URL to each loaded driver in turn.65*66* <P>The driver should throw an <code>SQLException</code> if it is the right67* driver to connect to the given URL but has trouble connecting to68* the database.69*70* <P>The {@code Properties} argument can be used to pass71* arbitrary string tag/value pairs as connection arguments.72* Normally at least "user" and "password" properties should be73* included in the {@code Properties} object.74* <p>75* <B>Note:</B> If a property is specified as part of the {@code url} and76* is also specified in the {@code Properties} object, it is77* implementation-defined as to which value will take precedence. For78* maximum portability, an application should only specify a property once.79*80* @param url the URL of the database to which to connect81* @param info a list of arbitrary string tag/value pairs as82* connection arguments. Normally at least a "user" and83* "password" property should be included.84* @return a <code>Connection</code> object that represents a85* connection to the URL86* @exception SQLException if a database access error occurs or the url is87* {@code null}88*/89Connection connect(String url, java.util.Properties info)90throws SQLException;9192/**93* Retrieves whether the driver thinks that it can open a connection94* to the given URL. Typically drivers will return <code>true</code> if they95* understand the sub-protocol specified in the URL and <code>false</code> if96* they do not.97*98* @param url the URL of the database99* @return <code>true</code> if this driver understands the given URL;100* <code>false</code> otherwise101* @exception SQLException if a database access error occurs or the url is102* {@code null}103*/104boolean acceptsURL(String url) throws SQLException;105106107/**108* Gets information about the possible properties for this driver.109* <P>110* The <code>getPropertyInfo</code> method is intended to allow a generic111* GUI tool to discover what properties it should prompt112* a human for in order to get113* enough information to connect to a database. Note that depending on114* the values the human has supplied so far, additional values may become115* necessary, so it may be necessary to iterate though several calls116* to the <code>getPropertyInfo</code> method.117*118* @param url the URL of the database to which to connect119* @param info a proposed list of tag/value pairs that will be sent on120* connect open121* @return an array of <code>DriverPropertyInfo</code> objects describing122* possible properties. This array may be an empty array if123* no properties are required.124* @exception SQLException if a database access error occurs125*/126DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)127throws SQLException;128129130/**131* Retrieves the driver's major version number. Initially this should be 1.132*133* @return this driver's major version number134*/135int getMajorVersion();136137/**138* Gets the driver's minor version number. Initially this should be 0.139* @return this driver's minor version number140*/141int getMinorVersion();142143144/**145* Reports whether this driver is a genuine JDBC146* Compliant™ driver.147* A driver may only report <code>true</code> here if it passes the JDBC148* compliance tests; otherwise it is required to return <code>false</code>.149* <P>150* JDBC compliance requires full support for the JDBC API and full support151* for SQL 92 Entry Level. It is expected that JDBC compliant drivers will152* be available for all the major commercial databases.153* <P>154* This method is not intended to encourage the development of non-JDBC155* compliant drivers, but is a recognition of the fact that some vendors156* are interested in using the JDBC API and framework for lightweight157* databases that do not support full database functionality, or for158* special databases such as document information retrieval where a SQL159* implementation may not be feasible.160* @return <code>true</code> if this driver is JDBC Compliant; <code>false</code>161* otherwise162*/163boolean jdbcCompliant();164165//------------------------- JDBC 4.1 -----------------------------------166167/**168* Return the parent Logger of all the Loggers used by this driver. This169* should be the Logger farthest from the root Logger that is170* still an ancestor of all of the Loggers used by this driver. Configuring171* this Logger will affect all of the log messages generated by the driver.172* In the worst case, this may be the root Logger.173*174* @return the parent Logger for this driver175* @throws SQLFeatureNotSupportedException if the driver does not use176* {@code java.util.logging}.177* @since 1.7178*/179public Logger getParentLogger() throws SQLFeatureNotSupportedException;180}181182183