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