Driver
Stay organized with collections
Save and categorize content based on your preferences.
The interface that every driver class must implement.
The Java SQL framework allows for multiple database drivers.
Each driver should supply a class that implements
the Driver interface.
The DriverManager will try to load as many drivers as it can
find and then for any given connection request, it will ask each
driver in turn to try to connect to the target URL.
It is strongly recommended that each Driver class should be
small and standalone so that the Driver class can be loaded and
queried without bringing in vast quantities of supporting code.
When a Driver class is loaded, it should create an instance of
itself and register it with the DriverManager. This means that a
user can load and register a driver by calling
Class.forName("foo.bah.Driver")
Public Method Summary
abstract
boolean
|
acceptsURL( String url)
Retrieves whether the driver thinks that it can open a connection
to the given URL.
|
abstract
Connection
|
|
abstract
int
|
|
abstract
int
|
|
abstract
DriverPropertyInfo[]
|
|
abstract
boolean
|
jdbcCompliant()
Reports whether this driver is a genuine JDBC
CompliantTM driver.
|
Public Methods
public
abstract
boolean
acceptsURL
(String url)
Retrieves whether the driver thinks that it can open a connection
to the given URL. Typically drivers will return true
if they
understand the subprotocol specified in the URL and false
if
they do not.
Parameters
url |
the URL of the database |
Returns
true
if this driver understands the given URL;
false
otherwise
Attempts to make a database connection to the given URL.
The driver should return "null" if it realizes it is the wrong kind
of driver to connect to the given URL. This will be common, as when
the JDBC driver manager is asked to connect to a given URL it passes
the URL to each loaded driver in turn.
The driver should throw an SQLException
if it is the right
driver to connect to the given URL but has trouble connecting to
the database.
The java.util.Properties
argument can be used to pass
arbitrary string tag/value pairs as connection arguments.
Normally at least "user" and "password" properties should be
included in the Properties
object.
Parameters
url |
the URL of the database to which to connect |
info |
a list of arbitrary string tag/value pairs as
connection arguments. Normally at least a "user" and
"password" property should be included. |
Returns
- a
Connection
object that represents a
connection to the URL
public
abstract
int
getMajorVersion
()
Retrieves the driver's major version number. Initially this should be 1.
Returns
- this driver's major version number
public
abstract
int
getMinorVersion
()
Gets the driver's minor version number. Initially this should be 0.
Returns
- this driver's minor version number
Gets information about the possible properties for this driver.
The getPropertyInfo
method is intended to allow a generic
GUI tool to discover what properties it should prompt
a human for in order to get
enough information to connect to a database. Note that depending on
the values the human has supplied so far, additional values may become
necessary, so it may be necessary to iterate though several calls
to the getPropertyInfo
method.
Parameters
url |
the URL of the database to which to connect |
info |
a proposed list of tag/value pairs that will be sent on
connect open |
Returns
- an array of
DriverPropertyInfo
objects describing
possible properties. This array may be an empty array if
no properties are required.
public
abstract
boolean
jdbcCompliant
()
Reports whether this driver is a genuine JDBC
CompliantTM driver.
A driver may only report true
here if it passes the JDBC
compliance tests; otherwise it is required to return false
.
JDBC compliance requires full support for the JDBC API and full support
for SQL 92 Entry Level. It is expected that JDBC compliant drivers will
be available for all the major commercial databases.
This method is not intended to encourage the development of non-JDBC
compliant drivers, but is a recognition of the fact that some vendors
are interested in using the JDBC API and framework for lightweight
databases that do not support full database functionality, or for
special databases such as document information retrieval where a SQL
implementation may not be feasible.
Returns
true
if this driver is JDBC Compliant; false
otherwise
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eDriver\u003c/code\u003e interface is implemented by every database driver class in the Java SQL framework to enable connections to various database systems.\u003c/p\u003e\n"],["\u003cp\u003eEach \u003ccode\u003eDriver\u003c/code\u003e is responsible for establishing connections to a specified database URL, indicated by its \u003ccode\u003econnect\u003c/code\u003e method and validated through \u003ccode\u003eacceptsURL\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDriver\u003c/code\u003e implementations offer details about their version using methods \u003ccode\u003egetMajorVersion\u003c/code\u003e and \u003ccode\u003egetMinorVersion\u003c/code\u003e, as well as property information via \u003ccode\u003egetPropertyInfo\u003c/code\u003e for connection configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ejdbcCompliant\u003c/code\u003e method reveals if the driver aligns with JDBC standards, implying complete support for JDBC API and entry-level SQL 92 functionality.\u003c/p\u003e\n"],["\u003cp\u003eUsers typically register a \u003ccode\u003eDriver\u003c/code\u003e through \u003ccode\u003eClass.forName\u003c/code\u003e, allowing the \u003ccode\u003eDriverManager\u003c/code\u003e to leverage it when connection requests matching its capabilities are made.\u003c/p\u003e\n"]]],[],null,["# Driver\n\npublic interface **Driver** \nThe interface that every driver class must implement.\n\nThe Java SQL framework allows for multiple database drivers.\n\nEach driver should supply a class that implements\nthe Driver interface.\n\nThe DriverManager will try to load as many drivers as it can\nfind and then for any given connection request, it will ask each\ndriver in turn to try to connect to the target URL.\n\nIt is strongly recommended that each Driver class should be\nsmall and standalone so that the Driver class can be loaded and\nqueried without bringing in vast quantities of supporting code.\n\nWhen a Driver class is loaded, it should create an instance of\nitself and register it with the DriverManager. This means that a\nuser can load and register a driver by calling \n\n Class.forName(\"foo.bah.Driver\")\n \n\u003cbr /\u003e\n\n##### See Also\n\n- [DriverManager](../../../reference/java/sql/DriverManager.html)\n- [Connection](../../../reference/java/sql/Connection.html) \n\n### Public Method Summary\n\n|----------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract boolean | [acceptsURL](../../../reference/java/sql/Driver.html#acceptsURL(java.lang.String))([String](../../../reference/java/lang/String.html) url) Retrieves whether the driver thinks that it can open a connection to the given URL. |\n| abstract [Connection](../../../reference/java/sql/Connection.html) | [connect](../../../reference/java/sql/Driver.html#connect(java.lang.String,%20java.util.Properties))([String](../../../reference/java/lang/String.html) url, [Properties](../../../reference/java/util/Properties.html) info) Attempts to make a database connection to the given URL. |\n| abstract int | [getMajorVersion](../../../reference/java/sql/Driver.html#getMajorVersion())() Retrieves the driver's major version number. |\n| abstract int | [getMinorVersion](../../../reference/java/sql/Driver.html#getMinorVersion())() Gets the driver's minor version number. |\n| abstract [DriverPropertyInfo\\[\\]](../../../reference/java/sql/DriverPropertyInfo.html) | [getPropertyInfo](../../../reference/java/sql/Driver.html#getPropertyInfo(java.lang.String,%20java.util.Properties))([String](../../../reference/java/lang/String.html) url, [Properties](../../../reference/java/util/Properties.html) info) Gets information about the possible properties for this driver. |\n| abstract boolean | [jdbcCompliant](../../../reference/java/sql/Driver.html#jdbcCompliant())() Reports whether this driver is a genuine JDBC Compliant^TM^ driver. |\n\nPublic Methods\n--------------\n\n#### public abstract boolean\n**acceptsURL**\n([String](../../../reference/java/lang/String.html) url)\n\nRetrieves whether the driver thinks that it can open a connection\nto the given URL. Typically drivers will return `true` if they\nunderstand the subprotocol specified in the URL and `false` if\nthey do not. \n\n##### Parameters\n\n| url | the URL of the database |\n|-----|-------------------------|\n\n##### Returns\n\n- `true` if this driver understands the given URL; `false` otherwise \n\n##### Throws\n\n| [SQLException](../../../reference/java/sql/SQLException.html) | if a database access error occurs |\n|---------------------------------------------------------------|-----------------------------------|\n\n#### public abstract [Connection](../../../reference/java/sql/Connection.html)\n**connect**\n([String](../../../reference/java/lang/String.html) url, [Properties](../../../reference/java/util/Properties.html) info)\n\nAttempts to make a database connection to the given URL.\nThe driver should return \"null\" if it realizes it is the wrong kind\nof driver to connect to the given URL. This will be common, as when\nthe JDBC driver manager is asked to connect to a given URL it passes\nthe URL to each loaded driver in turn.\n\nThe driver should throw an `SQLException` if it is the right\ndriver to connect to the given URL but has trouble connecting to\nthe database.\n\nThe `java.util.Properties` argument can be used to pass\narbitrary string tag/value pairs as connection arguments.\nNormally at least \"user\" and \"password\" properties should be\nincluded in the `Properties` object. \n\n##### Parameters\n\n| url | the URL of the database to which to connect |\n| info | a list of arbitrary string tag/value pairs as connection arguments. Normally at least a \"user\" and \"password\" property should be included. |\n|------|--------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- a `Connection` object that represents a connection to the URL \n\n##### Throws\n\n| [SQLException](../../../reference/java/sql/SQLException.html) | if a database access error occurs |\n|---------------------------------------------------------------|-----------------------------------|\n\n#### public abstract int\n**getMajorVersion**\n()\n\nRetrieves the driver's major version number. Initially this should be 1. \n\n##### Returns\n\n- this driver's major version number \n\n#### public abstract int\n**getMinorVersion**\n()\n\nGets the driver's minor version number. Initially this should be 0. \n\n##### Returns\n\n- this driver's minor version number \n\n#### public abstract [DriverPropertyInfo\\[\\]](../../../reference/java/sql/DriverPropertyInfo.html)\n**getPropertyInfo**\n([String](../../../reference/java/lang/String.html) url, [Properties](../../../reference/java/util/Properties.html) info)\n\nGets information about the possible properties for this driver.\n\n\nThe `getPropertyInfo` method is intended to allow a generic\nGUI tool to discover what properties it should prompt\na human for in order to get\nenough information to connect to a database. Note that depending on\nthe values the human has supplied so far, additional values may become\nnecessary, so it may be necessary to iterate though several calls\nto the `getPropertyInfo` method. \n\n##### Parameters\n\n| url | the URL of the database to which to connect |\n| info | a proposed list of tag/value pairs that will be sent on connect open |\n|------|----------------------------------------------------------------------|\n\n##### Returns\n\n- an array of `DriverPropertyInfo` objects describing possible properties. This array may be an empty array if no properties are required. \n\n##### Throws\n\n| [SQLException](../../../reference/java/sql/SQLException.html) | if a database access error occurs |\n|---------------------------------------------------------------|-----------------------------------|\n\n#### public abstract boolean\n**jdbcCompliant**\n()\n\nReports whether this driver is a genuine JDBC\nCompliant^TM^ driver.\nA driver may only report `true` here if it passes the JDBC\ncompliance tests; otherwise it is required to return `false`.\n\n\nJDBC compliance requires full support for the JDBC API and full support\nfor SQL 92 Entry Level. It is expected that JDBC compliant drivers will\nbe available for all the major commercial databases.\n\n\nThis method is not intended to encourage the development of non-JDBC\ncompliant drivers, but is a recognition of the fact that some vendors\nare interested in using the JDBC API and framework for lightweight\ndatabases that do not support full database functionality, or for\nspecial databases such as document information retrieval where a SQL\nimplementation may not be feasible. \n\n##### Returns\n\n- `true` if this driver is JDBC Compliant; `false` otherwise"]]