1 /*
2  * Copyright (c) 1996, 2010, 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  * <pre>
49  *   <code>Class.forName("foo.bah.Driver")</code>
50  * </pre>
51  *
52  * @see DriverManager
53  * @see Connection
54  */
55 public interface Driver {
56 
57     /**
58      * Attempts to make a database connection to the given URL.
59      * The driver should return "null" if it realizes it is the wrong kind
60      * of driver to connect to the given URL.  This will be common, as when
61      * the JDBC driver manager is asked to connect to a given URL it passes
62      * the URL to each loaded driver in turn.
63      *
64      * <P>The driver should throw an <code>SQLException</code> if it is the right
65      * driver to connect to the given URL but has trouble connecting to
66      * the database.
67      *
68      * <P>The <code>java.util.Properties</code> argument can be used to pass
69      * arbitrary string tag/value pairs as connection arguments.
70      * Normally at least "user" and "password" properties should be
71      * included in the <code>Properties</code> object.
72      *
73      * @param url the URL of the database to which to connect
74      * @param info a list of arbitrary string tag/value pairs as
75      * connection arguments. Normally at least a "user" and
76      * "password" property should be included.
77      * @return a <code>Connection</code> object that represents a
78      *         connection to the URL
79      * @exception SQLException if a database access error occurs
80      */
connect(String url, java.util.Properties info)81     Connection connect(String url, java.util.Properties info)
82         throws SQLException;
83 
84     /**
85      * Retrieves whether the driver thinks that it can open a connection
86      * to the given URL.  Typically drivers will return <code>true</code> if they
87      * understand the subprotocol specified in the URL and <code>false</code> if
88      * they do not.
89      *
90      * @param url the URL of the database
91      * @return <code>true</code> if this driver understands the given URL;
92      *         <code>false</code> otherwise
93      * @exception SQLException if a database access error occurs
94      */
acceptsURL(String url)95     boolean acceptsURL(String url) throws SQLException;
96 
97 
98     /**
99      * Gets information about the possible properties for this driver.
100      * <P>
101      * The <code>getPropertyInfo</code> method is intended to allow a generic
102      * GUI tool to discover what properties it should prompt
103      * a human for in order to get
104      * enough information to connect to a database.  Note that depending on
105      * the values the human has supplied so far, additional values may become
106      * necessary, so it may be necessary to iterate though several calls
107      * to the <code>getPropertyInfo</code> method.
108      *
109      * @param url the URL of the database to which to connect
110      * @param info a proposed list of tag/value pairs that will be sent on
111      *          connect open
112      * @return an array of <code>DriverPropertyInfo</code> objects describing
113      *          possible properties.  This array may be an empty array if
114      *          no properties are required.
115      * @exception SQLException if a database access error occurs
116      */
getPropertyInfo(String url, java.util.Properties info)117     DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)
118                          throws SQLException;
119 
120 
121     /**
122      * Retrieves the driver's major version number. Initially this should be 1.
123      *
124      * @return this driver's major version number
125      */
getMajorVersion()126     int getMajorVersion();
127 
128     /**
129      * Gets the driver's minor version number. Initially this should be 0.
130      * @return this driver's minor version number
131      */
getMinorVersion()132     int getMinorVersion();
133 
134 
135     /**
136      * Reports whether this driver is a genuine JDBC
137      * Compliant<sup><font size=-2>TM</font></sup> driver.
138      * A driver may only report <code>true</code> here if it passes the JDBC
139      * compliance tests; otherwise it is required to return <code>false</code>.
140      * <P>
141      * JDBC compliance requires full support for the JDBC API and full support
142      * for SQL 92 Entry Level.  It is expected that JDBC compliant drivers will
143      * be available for all the major commercial databases.
144      * <P>
145      * This method is not intended to encourage the development of non-JDBC
146      * compliant drivers, but is a recognition of the fact that some vendors
147      * are interested in using the JDBC API and framework for lightweight
148      * databases that do not support full database functionality, or for
149      * special databases such as document information retrieval where a SQL
150      * implementation may not be feasible.
151      * @return <code>true</code> if this driver is JDBC Compliant; <code>false</code>
152      *         otherwise
153      */
jdbcCompliant()154     boolean jdbcCompliant();
155 
156 }
157