001: /*
002: * Copyright 1996-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package java.sql;
027:
028: /**
029: * The interface that every driver class must implement.
030: * <P>The Java SQL framework allows for multiple database drivers.
031: *
032: * <P>Each driver should supply a class that implements
033: * the Driver interface.
034: *
035: * <P>The DriverManager will try to load as many drivers as it can
036: * find and then for any given connection request, it will ask each
037: * driver in turn to try to connect to the target URL.
038: *
039: * <P>It is strongly recommended that each Driver class should be
040: * small and standalone so that the Driver class can be loaded and
041: * queried without bringing in vast quantities of supporting code.
042: *
043: * <P>When a Driver class is loaded, it should create an instance of
044: * itself and register it with the DriverManager. This means that a
045: * user can load and register a driver by calling
046: * <pre>
047: * <code>Class.forName("foo.bah.Driver")</code>
048: * </pre>
049: *
050: * @see DriverManager
051: * @see Connection
052: */
053: public interface Driver {
054:
055: /**
056: * Attempts to make a database connection to the given URL.
057: * The driver should return "null" if it realizes it is the wrong kind
058: * of driver to connect to the given URL. This will be common, as when
059: * the JDBC driver manager is asked to connect to a given URL it passes
060: * the URL to each loaded driver in turn.
061: *
062: * <P>The driver should throw an <code>SQLException</code> if it is the right
063: * driver to connect to the given URL but has trouble connecting to
064: * the database.
065: *
066: * <P>The <code>java.util.Properties</code> argument can be used to pass
067: * arbitrary string tag/value pairs as connection arguments.
068: * Normally at least "user" and "password" properties should be
069: * included in the <code>Properties</code> object.
070: *
071: * @param url the URL of the database to which to connect
072: * @param info a list of arbitrary string tag/value pairs as
073: * connection arguments. Normally at least a "user" and
074: * "password" property should be included.
075: * @return a <code>Connection</code> object that represents a
076: * connection to the URL
077: * @exception SQLException if a database access error occurs
078: */
079: Connection connect(String url, java.util.Properties info)
080: throws SQLException;
081:
082: /**
083: * Retrieves whether the driver thinks that it can open a connection
084: * to the given URL. Typically drivers will return <code>true</code> if they
085: * understand the subprotocol specified in the URL and <code>false</code> if
086: * they do not.
087: *
088: * @param url the URL of the database
089: * @return <code>true</code> if this driver understands the given URL;
090: * <code>false</code> otherwise
091: * @exception SQLException if a database access error occurs
092: */
093: boolean acceptsURL(String url) throws SQLException;
094:
095: /**
096: * Gets information about the possible properties for this driver.
097: * <P>
098: * The <code>getPropertyInfo</code> method is intended to allow a generic
099: * GUI tool to discover what properties it should prompt
100: * a human for in order to get
101: * enough information to connect to a database. Note that depending on
102: * the values the human has supplied so far, additional values may become
103: * necessary, so it may be necessary to iterate though several calls
104: * to the <code>getPropertyInfo</code> method.
105: *
106: * @param url the URL of the database to which to connect
107: * @param info a proposed list of tag/value pairs that will be sent on
108: * connect open
109: * @return an array of <code>DriverPropertyInfo</code> objects describing
110: * possible properties. This array may be an empty array if
111: * no properties are required.
112: * @exception SQLException if a database access error occurs
113: */
114: DriverPropertyInfo[] getPropertyInfo(String url,
115: java.util.Properties info) throws SQLException;
116:
117: /**
118: * Retrieves the driver's major version number. Initially this should be 1.
119: *
120: * @return this driver's major version number
121: */
122: int getMajorVersion();
123:
124: /**
125: * Gets the driver's minor version number. Initially this should be 0.
126: * @return this driver's minor version number
127: */
128: int getMinorVersion();
129:
130: /**
131: * Reports whether this driver is a genuine JDBC
132: * Compliant<sup><font size=-2>TM</font></sup> driver.
133: * A driver may only report <code>true</code> here if it passes the JDBC
134: * compliance tests; otherwise it is required to return <code>false</code>.
135: * <P>
136: * JDBC compliance requires full support for the JDBC API and full support
137: * for SQL 92 Entry Level. It is expected that JDBC compliant drivers will
138: * be available for all the major commercial databases.
139: * <P>
140: * This method is not intended to encourage the development of non-JDBC
141: * compliant drivers, but is a recognition of the fact that some vendors
142: * are interested in using the JDBC API and framework for lightweight
143: * databases that do not support full database functionality, or for
144: * special databases such as document information retrieval where a SQL
145: * implementation may not be feasible.
146: * @return <code>true</code> if this driver is JDBC Compliant; <code>false</code>
147: * otherwise
148: */
149: boolean jdbcCompliant();
150: }
|