Class NonRegisteringDriver

java.lang.Object
com.mysql.jdbc.NonRegisteringDriver
All Implemented Interfaces:
Driver
Direct Known Subclasses:
Driver, NonRegisteringReplicationDriver

public class NonRegisteringDriver extends Object implements Driver
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 doing Class.forName("foo.bah.Driver")

  • Field Details

    • LOADBALANCE_URL_PREFIX

      public static final String LOADBALANCE_URL_PREFIX
      See Also:
    • PLATFORM

      public static final String PLATFORM
    • OS

      public static final String OS
    • LICENSE

      public static final String LICENSE
      See Also:
    • RUNTIME_VENDOR

      public static final String RUNTIME_VENDOR
    • RUNTIME_VERSION

      public static final String RUNTIME_VERSION
    • VERSION

      public static final String VERSION
      See Also:
    • NAME

      public static final String NAME
      See Also:
    • DBNAME_PROPERTY_KEY

      public static final String DBNAME_PROPERTY_KEY
      Key used to retreive the database value from the properties instance passed to the driver.
      See Also:
    • DEBUG

      public static final boolean DEBUG
      Should the driver generate debugging output?
      See Also:
    • HOST_NAME_INDEX

      public static final int HOST_NAME_INDEX
      Index for hostname coming out of parseHostPortPair().
      See Also:
    • HOST_PROPERTY_KEY

      public static final String HOST_PROPERTY_KEY
      Key used to retreive the hostname value from the properties instance passed to the driver.
      See Also:
    • NUM_HOSTS_PROPERTY_KEY

      public static final String NUM_HOSTS_PROPERTY_KEY
      See Also:
    • PASSWORD_PROPERTY_KEY

      public static final String PASSWORD_PROPERTY_KEY
      Key used to retreive the password value from the properties instance passed to the driver.
      See Also:
    • PORT_NUMBER_INDEX

      public static final int PORT_NUMBER_INDEX
      Index for port # coming out of parseHostPortPair().
      See Also:
    • PORT_PROPERTY_KEY

      public static final String PORT_PROPERTY_KEY
      Key used to retreive the port number value from the properties instance passed to the driver.
      See Also:
    • PROPERTIES_TRANSFORM_KEY

      public static final String PROPERTIES_TRANSFORM_KEY
      See Also:
    • TRACE

      public static final boolean TRACE
      Should the driver generate method-call traces?
      See Also:
    • USE_CONFIG_PROPERTY_KEY

      public static final String USE_CONFIG_PROPERTY_KEY
      See Also:
    • USER_PROPERTY_KEY

      public static final String USER_PROPERTY_KEY
      Key used to retreive the username value from the properties instance passed to the driver.
      See Also:
    • PROTOCOL_PROPERTY_KEY

      public static final String PROTOCOL_PROPERTY_KEY
      See Also:
    • PATH_PROPERTY_KEY

      public static final String PATH_PROPERTY_KEY
      See Also:
  • Constructor Details

    • NonRegisteringDriver

      public NonRegisteringDriver() throws SQLException
      Construct a new driver and register it with DriverManager
      Throws:
      SQLException - if a database error occurs.
  • Method Details

    • getOSName

      public static String getOSName()
    • getPlatform

      public static String getPlatform()
    • getMajorVersionInternal

      static int getMajorVersionInternal()
      Gets the drivers major version number
      Returns:
      the drivers major version number
    • getMinorVersionInternal

      static int getMinorVersionInternal()
      Get the drivers minor version number
      Returns:
      the drivers minor version number
    • parseHostPortPair

      protected static String[] parseHostPortPair(String hostPortPair) throws SQLException
      Parses hostPortPair in the form of [host][:port] into an array, with the element of index HOST_NAME_INDEX being the host (or null if not specified), and the element of index PORT_NUMBER_INDEX being the port (or null if not specified).
      Parameters:
      hostPortPair - host and port in form of of [host][:port]
      Returns:
      array containing host and port as Strings
      Throws:
      SQLException - if a parse error occurs
    • acceptsURL

      public boolean acceptsURL(String url) throws SQLException
      Typically, drivers will return true if they understand the subprotocol specified in the URL and false if they don't. This driver's protocols start with jdbc:mysql:
      Specified by:
      acceptsURL in interface Driver
      Parameters:
      url - the URL of the driver
      Returns:
      true if this driver accepts the given URL
      Throws:
      SQLException - if a database access error occurs or the url is null
      See Also:
    • connect

      public Connection connect(String url, Properties info) throws SQLException
      Try 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 driverManager is asked to connect to a given URL, it passes the URL to each loaded driver in turn.

      The driver should raise an SQLException if the URL is null or 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. These properties take precedence over any properties sent in the URL.

      MySQL protocol takes the form:

      jdbc:mysql://host:port/database
      

      Specified by:
      connect in interface Driver
      Parameters:
      url - the URL of the database to connect to
      info - a list of arbitrary tag/value pairs as connection arguments
      Returns:
      a connection to the URL or null if it isn't us
      Throws:
      SQLException - if a database access error occurs or the url is null
      See Also:
    • connectReplicationConnection

      protected Connection connectReplicationConnection(String url, Properties info) throws SQLException
      Throws:
      SQLException
    • database

      public String database(Properties props)
      Returns the database property from props
      Parameters:
      props - the Properties to look for the database property.
      Returns:
      the database name.
    • getMajorVersion

      public int getMajorVersion()
      Gets the drivers major version number
      Specified by:
      getMajorVersion in interface Driver
      Returns:
      the drivers major version number
    • getMinorVersion

      public int getMinorVersion()
      Get the drivers minor version number
      Specified by:
      getMinorVersion in interface Driver
      Returns:
      the drivers minor version number
    • getPropertyInfo

      public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException
      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 through several calls to getPropertyInfo

      Specified by:
      getPropertyInfo in interface Driver
      Parameters:
      url - the Url of the database to connect to
      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
      Throws:
      SQLException - if a database-access error occurs
      See Also:
    • host

      public String host(Properties props)
      Returns the hostname property
      Parameters:
      props - the java.util.Properties instance to retrieve the hostname from.
      Returns:
      the hostname
    • jdbcCompliant

      public boolean jdbcCompliant()
      Report whether the driver is a genuine JDBC compliant 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.

      MySQL is not SQL92 compliant

      Specified by:
      jdbcCompliant in interface Driver
      Returns:
      is this driver JDBC compliant?
    • parseURL

      public Properties parseURL(String url, Properties defaults) throws SQLException
      Throws:
      SQLException
    • port

      public int port(Properties props)
      Returns the port number property
      Parameters:
      props - the properties to get the port number from
      Returns:
      the port number
    • property

      public String property(String name, Properties props)
      Returns the given property from props
      Parameters:
      name - the property name
      props - the property instance to look in
      Returns:
      the property value, or null if not found.
    • expandHostKeyValues

      public static Properties expandHostKeyValues(String host)
      Expands hosts of the form address=(protocol=tcp)(host=localhost)(port=3306) into a java.util.Properties. Special characters (in this case () and =) must be quoted. Any values that are string-quoted ("" or '') are also stripped of quotes.
    • isHostPropertiesList

      public static boolean isHostPropertiesList(String host)