blob: cebf6cab180a71c0de9919cc686bee2013f5ff16 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1996-2005 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package java.sql;
27
28/**
29 * The interface that every driver class must implement.
30 * <P>The Java SQL framework allows for multiple database drivers.
31 *
32 * <P>Each driver should supply a class that implements
33 * the Driver interface.
34 *
35 * <P>The DriverManager will try to load as many drivers as it can
36 * find and then for any given connection request, it will ask each
37 * driver in turn to try to connect to the target URL.
38 *
39 * <P>It is strongly recommended that each Driver class should be
40 * small and standalone so that the Driver class can be loaded and
41 * queried without bringing in vast quantities of supporting code.
42 *
43 * <P>When a Driver class is loaded, it should create an instance of
44 * itself and register it with the DriverManager. This means that a
45 * user can load and register a driver by calling
46 * <pre>
47 * <code>Class.forName("foo.bah.Driver")</code>
48 * </pre>
49 *
50 * @see DriverManager
51 * @see Connection
52 */
53public interface Driver {
54
55 /**
56 * Attempts to make a database connection to the given URL.
57 * The driver should return "null" if it realizes it is the wrong kind
58 * of driver to connect to the given URL. This will be common, as when
59 * the JDBC driver manager is asked to connect to a given URL it passes
60 * the URL to each loaded driver in turn.
61 *
62 * <P>The driver should throw an <code>SQLException</code> if it is the right
63 * driver to connect to the given URL but has trouble connecting to
64 * the database.
65 *
66 * <P>The <code>java.util.Properties</code> argument can be used to pass
67 * arbitrary string tag/value pairs as connection arguments.
68 * Normally at least "user" and "password" properties should be
69 * included in the <code>Properties</code> object.
70 *
71 * @param url the URL of the database to which to connect
72 * @param info a list of arbitrary string tag/value pairs as
73 * connection arguments. Normally at least a "user" and
74 * "password" property should be included.
75 * @return a <code>Connection</code> object that represents a
76 * connection to the URL
77 * @exception SQLException if a database access error occurs
78 */
79 Connection connect(String url, java.util.Properties info)
80 throws SQLException;
81
82 /**
83 * Retrieves whether the driver thinks that it can open a connection
84 * to the given URL. Typically drivers will return <code>true</code> if they
85 * understand the subprotocol specified in the URL and <code>false</code> if
86 * they do not.
87 *
88 * @param url the URL of the database
89 * @return <code>true</code> if this driver understands the given URL;
90 * <code>false</code> otherwise
91 * @exception SQLException if a database access error occurs
92 */
93 boolean acceptsURL(String url) throws SQLException;
94
95
96 /**
97 * Gets information about the possible properties for this driver.
98 * <P>
99 * The <code>getPropertyInfo</code> method is intended to allow a generic
100 * GUI tool to discover what properties it should prompt
101 * a human for in order to get
102 * enough information to connect to a database. Note that depending on
103 * the values the human has supplied so far, additional values may become
104 * necessary, so it may be necessary to iterate though several calls
105 * to the <code>getPropertyInfo</code> method.
106 *
107 * @param url the URL of the database to which to connect
108 * @param info a proposed list of tag/value pairs that will be sent on
109 * connect open
110 * @return an array of <code>DriverPropertyInfo</code> objects describing
111 * possible properties. This array may be an empty array if
112 * no properties are required.
113 * @exception SQLException if a database access error occurs
114 */
115 DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)
116 throws SQLException;
117
118
119 /**
120 * Retrieves the driver's major version number. Initially this should be 1.
121 *
122 * @return this driver's major version number
123 */
124 int getMajorVersion();
125
126 /**
127 * Gets the driver's minor version number. Initially this should be 0.
128 * @return this driver's minor version number
129 */
130 int getMinorVersion();
131
132
133 /**
134 * Reports whether this driver is a genuine JDBC
135 * Compliant<sup><font size=-2>TM</font></sup> driver.
136 * A driver may only report <code>true</code> here if it passes the JDBC
137 * compliance tests; otherwise it is required to return <code>false</code>.
138 * <P>
139 * JDBC compliance requires full support for the JDBC API and full support
140 * for SQL 92 Entry Level. It is expected that JDBC compliant drivers will
141 * be available for all the major commercial databases.
142 * <P>
143 * This method is not intended to encourage the development of non-JDBC
144 * compliant drivers, but is a recognition of the fact that some vendors
145 * are interested in using the JDBC API and framework for lightweight
146 * databases that do not support full database functionality, or for
147 * special databases such as document information retrieval where a SQL
148 * implementation may not be feasible.
149 * @return <code>true</code> if this driver is JDBC Compliant; <code>false</code>
150 * otherwise
151 */
152 boolean jdbcCompliant();
153}