/jdk-11.0.2/src/java.sql/java/sql/Driver.java

https://github.com/zxiaofan/JDK · Java · 182 lines · 13 code · 14 blank · 155 comment · 0 complexity · 2051efc6678843790d5e627fb5fa0e7c MD5 · raw file

  1. /*
  2. * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
  3. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. *
  5. *
  6. *
  7. *
  8. *
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *
  15. *
  16. *
  17. *
  18. *
  19. *
  20. *
  21. *
  22. *
  23. *
  24. */
  25. package java.sql;
  26. import java.util.logging.Logger;
  27. /**
  28. * The interface that every driver class must implement.
  29. * <P>The Java SQL framework allows for multiple database drivers.
  30. *
  31. * <P>Each driver should supply a class that implements
  32. * the Driver interface.
  33. *
  34. * <P>The DriverManager will try to load as many drivers as it can
  35. * find and then for any given connection request, it will ask each
  36. * driver in turn to try to connect to the target URL.
  37. *
  38. * <P>It is strongly recommended that each Driver class should be
  39. * small and standalone so that the Driver class can be loaded and
  40. * queried without bringing in vast quantities of supporting code.
  41. *
  42. * <P>When a Driver class is loaded, it should create an instance of
  43. * itself and register it with the DriverManager. This means that a
  44. * user can load and register a driver by calling:
  45. * <p>
  46. * {@code Class.forName("foo.bah.Driver")}
  47. * <p>
  48. * A JDBC driver may create a {@linkplain DriverAction} implementation in order
  49. * to receive notifications when {@linkplain DriverManager#deregisterDriver} has
  50. * been called.
  51. * @see DriverManager
  52. * @see Connection
  53. * @see DriverAction
  54. * @since 1.1
  55. */
  56. public interface Driver {
  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 Properties} 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} object.
  72. * <p>
  73. * <B>Note:</B> If a property is specified as part of the {@code url} and
  74. * is also specified in the {@code Properties} object, it is
  75. * implementation-defined as to which value will take precedence. For
  76. * maximum portability, an application should only specify a property once.
  77. *
  78. * @param url the URL of the database to which to connect
  79. * @param info a list of arbitrary string tag/value pairs as
  80. * connection arguments. Normally at least a "user" and
  81. * "password" property should be included.
  82. * @return a <code>Connection</code> object that represents a
  83. * connection to the URL
  84. * @exception SQLException if a database access error occurs or the url is
  85. * {@code null}
  86. */
  87. Connection connect(String url, java.util.Properties info)
  88. throws SQLException;
  89. /**
  90. * Retrieves whether the driver thinks that it can open a connection
  91. * to the given URL. Typically drivers will return <code>true</code> if they
  92. * understand the sub-protocol specified in the URL and <code>false</code> if
  93. * they do not.
  94. *
  95. * @param url the URL of the database
  96. * @return <code>true</code> if this driver understands the given URL;
  97. * <code>false</code> otherwise
  98. * @exception SQLException if a database access error occurs or the url is
  99. * {@code null}
  100. */
  101. boolean acceptsURL(String url) throws SQLException;
  102. /**
  103. * Gets information about the possible properties for this driver.
  104. * <P>
  105. * The <code>getPropertyInfo</code> method is intended to allow a generic
  106. * GUI tool to discover what properties it should prompt
  107. * a human for in order to get
  108. * enough information to connect to a database. Note that depending on
  109. * the values the human has supplied so far, additional values may become
  110. * necessary, so it may be necessary to iterate though several calls
  111. * to the <code>getPropertyInfo</code> method.
  112. *
  113. * @param url the URL of the database to which to connect
  114. * @param info a proposed list of tag/value pairs that will be sent on
  115. * connect open
  116. * @return an array of <code>DriverPropertyInfo</code> objects describing
  117. * possible properties. This array may be an empty array if
  118. * no properties are required.
  119. * @exception SQLException if a database access error occurs
  120. */
  121. DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)
  122. throws SQLException;
  123. /**
  124. * Retrieves the driver's major version number. Initially this should be 1.
  125. *
  126. * @return this driver's major version number
  127. */
  128. int getMajorVersion();
  129. /**
  130. * Gets the driver's minor version number. Initially this should be 0.
  131. * @return this driver's minor version number
  132. */
  133. int getMinorVersion();
  134. /**
  135. * Reports whether this driver is a genuine JDBC
  136. * Compliant&trade; driver.
  137. * A driver may only report <code>true</code> here if it passes the JDBC
  138. * compliance tests; otherwise it is required to return <code>false</code>.
  139. * <P>
  140. * JDBC compliance requires full support for the JDBC API and full support
  141. * for SQL 92 Entry Level. It is expected that JDBC compliant drivers will
  142. * be available for all the major commercial databases.
  143. * <P>
  144. * This method is not intended to encourage the development of non-JDBC
  145. * compliant drivers, but is a recognition of the fact that some vendors
  146. * are interested in using the JDBC API and framework for lightweight
  147. * databases that do not support full database functionality, or for
  148. * special databases such as document information retrieval where a SQL
  149. * implementation may not be feasible.
  150. * @return <code>true</code> if this driver is JDBC Compliant; <code>false</code>
  151. * otherwise
  152. */
  153. boolean jdbcCompliant();
  154. //------------------------- JDBC 4.1 -----------------------------------
  155. /**
  156. * Return the parent Logger of all the Loggers used by this driver. This
  157. * should be the Logger farthest from the root Logger that is
  158. * still an ancestor of all of the Loggers used by this driver. Configuring
  159. * this Logger will affect all of the log messages generated by the driver.
  160. * In the worst case, this may be the root Logger.
  161. *
  162. * @return the parent Logger for this driver
  163. * @throws SQLFeatureNotSupportedException if the driver does not use
  164. * {@code java.util.logging}.
  165. * @since 1.7
  166. */
  167. public Logger getParentLogger() throws SQLFeatureNotSupportedException;
  168. }