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