1. /*
  2. * @(#)Driver.java 1.16 01/11/29
  3. *
  4. * Copyright 2002 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 raise a SQLException 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 java.util.Properties argument can be used to passed arbitrary
  46. * string tag/value pairs as connection arguments.
  47. * Normally at least "user" and "password" properties should be
  48. * included in the Properties.
  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. * Returns true if the driver thinks that it can open a connection
  62. * to the given URL. Typically drivers will return true if they
  63. * understand the subprotocol specified in the URL and false if
  64. * they don't.
  65. *
  66. * @param url the URL of the database
  67. * @return true if this driver can connect to the given URL
  68. * @exception SQLException if a database access error occurs
  69. */
  70. boolean acceptsURL(String url) throws SQLException;
  71. /**
  72. * Gets information about the possible properties for this driver.
  73. * <p>The getPropertyInfo method is intended to allow a generic GUI tool to
  74. * discover what properties it should prompt a human for in order to get
  75. * enough information to connect to a database. Note that depending on
  76. * the values the human has supplied so far, additional values may become
  77. * necessary, so it may be necessary to iterate though several calls
  78. * to getPropertyInfo.
  79. *
  80. * @param url the URL of the database to which to connect
  81. * @param info a proposed list of tag/value pairs that will be sent on
  82. * connect open
  83. * @return an array of DriverPropertyInfo objects describing possible
  84. * properties. This array may be an empty array if no properties
  85. * are required.
  86. * @exception SQLException if a database access error occurs
  87. */
  88. DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)
  89. throws SQLException;
  90. /**
  91. * Gets the driver's major version number. Initially this should be 1.
  92. * @return this driver's major version number
  93. */
  94. int getMajorVersion();
  95. /**
  96. * Gets the driver's minor version number. Initially this should be 0.
  97. * @return this driver's minor version number
  98. */
  99. int getMinorVersion();
  100. /**
  101. * Reports whether this driver is a genuine JDBC
  102. * COMPLIANT<sup><font size=-2>TM</font></sup> driver.
  103. * A driver may only report true here if it passes the JDBC compliance
  104. * tests; otherwise it is required to return false.
  105. *
  106. * JDBC compliance requires full support for the JDBC API and full support
  107. * for SQL 92 Entry Level. It is expected that JDBC compliant drivers will
  108. * be available for all the major commercial databases.
  109. *
  110. * This method is not intended to encourage the development of non-JDBC
  111. * compliant drivers, but is a recognition of the fact that some vendors
  112. * are interested in using the JDBC API and framework for lightweight
  113. * databases that do not support full database functionality, or for
  114. * special databases such as document information retrieval where a SQL
  115. * implementation may not be feasible.
  116. */
  117. boolean jdbcCompliant();
  118. }