com.mysql.jdbc
Class NonRegisteringDriver

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

public class NonRegisteringDriver
extends java.lang.Object
implements java.sql.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")

See Also:
org.gjt.mm.mysql.Connection, Driver

Field Summary
static java.lang.String DBNAME_PROPERTY_KEY
          Key used to retreive the database value from the properties instance passed to the driver.
static boolean DEBUG
          Should the driver generate debugging output?
static int HOST_NAME_INDEX
          Index for hostname coming out of parseHostPortPair().
static java.lang.String HOST_PROPERTY_KEY
          Key used to retreive the hostname value from the properties instance passed to the driver.
static java.lang.String NUM_HOSTS_PROPERTY_KEY
           
static java.lang.String PASSWORD_PROPERTY_KEY
          Key used to retreive the password value from the properties instance passed to the driver.
static int PORT_NUMBER_INDEX
          Index for port # coming out of parseHostPortPair().
static java.lang.String PORT_PROPERTY_KEY
          Key used to retreive the port number value from the properties instance passed to the driver.
static java.lang.String PROPERTIES_TRANSFORM_KEY
           
static boolean TRACE
          Should the driver generate method-call traces?
static java.lang.String USE_CONFIG_PROPERTY_KEY
           
static java.lang.String USER_PROPERTY_KEY
          Key used to retreive the username value from the properties instance passed to the driver.
 
Constructor Summary
NonRegisteringDriver()
          Construct a new driver and register it with DriverManager
 
Method Summary
 boolean acceptsURL(java.lang.String url)
          Typically, drivers will return true if they understand the subprotocol specified in the URL and false if they don't.
 java.sql.Connection connect(java.lang.String url, java.util.Properties info)
          Try to make a database connection to the given URL.
protected  java.sql.Connection connectReplicationConnection(java.lang.String url, java.util.Properties info)
           
 java.lang.String database(java.util.Properties props)
          Returns the database property from props
 int getMajorVersion()
          Gets the drivers major version number
(package private) static int getMajorVersionInternal()
          Gets the drivers major version number
 int getMinorVersion()
          Get the drivers minor version number
(package private) static int getMinorVersionInternal()
          Get the drivers minor version number
 java.sql.DriverPropertyInfo[] getPropertyInfo(java.lang.String url, java.util.Properties info)
          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.
 java.lang.String host(java.util.Properties props)
          Returns the hostname property
 boolean jdbcCompliant()
          Report whether the driver is a genuine JDBC compliant driver.
protected static java.lang.String[] parseHostPortPair(java.lang.String hostPortPair)
          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).
 java.util.Properties parseURL(java.lang.String url, java.util.Properties defaults)
           
 int port(java.util.Properties props)
          Returns the port number property
 java.lang.String property(java.lang.String name, java.util.Properties props)
          Returns the given property from props
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DBNAME_PROPERTY_KEY

public static final java.lang.String DBNAME_PROPERTY_KEY
Key used to retreive the database value from the properties instance passed to the driver.

See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
Should the driver generate debugging output?

See Also:
Constant Field Values

HOST_NAME_INDEX

public static final int HOST_NAME_INDEX
Index for hostname coming out of parseHostPortPair().

See Also:
Constant Field Values

HOST_PROPERTY_KEY

public static final java.lang.String HOST_PROPERTY_KEY
Key used to retreive the hostname value from the properties instance passed to the driver.

See Also:
Constant Field Values

NUM_HOSTS_PROPERTY_KEY

public static final java.lang.String NUM_HOSTS_PROPERTY_KEY
See Also:
Constant Field Values

PASSWORD_PROPERTY_KEY

public static final java.lang.String PASSWORD_PROPERTY_KEY
Key used to retreive the password value from the properties instance passed to the driver.

See Also:
Constant Field Values

PORT_NUMBER_INDEX

public static final int PORT_NUMBER_INDEX
Index for port # coming out of parseHostPortPair().

See Also:
Constant Field Values

PORT_PROPERTY_KEY

public static final java.lang.String PORT_PROPERTY_KEY
Key used to retreive the port number value from the properties instance passed to the driver.

See Also:
Constant Field Values

PROPERTIES_TRANSFORM_KEY

public static final java.lang.String PROPERTIES_TRANSFORM_KEY
See Also:
Constant Field Values

TRACE

public static final boolean TRACE
Should the driver generate method-call traces?

See Also:
Constant Field Values

USE_CONFIG_PROPERTY_KEY

public static final java.lang.String USE_CONFIG_PROPERTY_KEY
See Also:
Constant Field Values

USER_PROPERTY_KEY

public static final java.lang.String USER_PROPERTY_KEY
Key used to retreive the username value from the properties instance passed to the driver.

See Also:
Constant Field Values
Constructor Detail

NonRegisteringDriver

public NonRegisteringDriver()
                     throws java.sql.SQLException
Construct a new driver and register it with DriverManager

Throws:
java.sql.SQLException - if a database error occurs.
Method Detail

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 java.lang.String[] parseHostPortPair(java.lang.String hostPortPair)
                                               throws java.sql.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:
java.sql.SQLException - if a parse error occurs

acceptsURL

public boolean acceptsURL(java.lang.String url)
                   throws java.sql.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 java.sql.Driver
Parameters:
url - the URL of the driver
Returns:
true if this driver accepts the given URL
Throws:
java.sql.SQLException - if a database-access error occurs
See Also:
Driver.acceptsURL(java.lang.String)

connect

public java.sql.Connection connect(java.lang.String url,
                                   java.util.Properties info)
                            throws java.sql.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 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.

My protocol takes the form:

 
 jdbc:mysql://host:port/database
 
 

Specified by:
connect in interface java.sql.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 isnt us
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
Driver.connect(java.lang.String, java.util.Properties)

connectReplicationConnection

protected java.sql.Connection connectReplicationConnection(java.lang.String url,
                                                           java.util.Properties info)
                                                    throws java.sql.SQLException
Throws:
java.sql.SQLException

database

public java.lang.String database(java.util.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 java.sql.Driver
Returns:
the drivers major version number

getMinorVersion

public int getMinorVersion()
Get the drivers minor version number

Specified by:
getMinorVersion in interface java.sql.Driver
Returns:
the drivers minor version number

getPropertyInfo

public java.sql.DriverPropertyInfo[] getPropertyInfo(java.lang.String url,
                                                     java.util.Properties info)
                                              throws java.sql.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 java.sql.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:
java.sql.SQLException - if a database-access error occurs
See Also:
Driver.getPropertyInfo(java.lang.String, java.util.Properties)

host

public java.lang.String host(java.util.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 java.sql.Driver
Returns:
is this driver JDBC compliant?

parseURL

public java.util.Properties parseURL(java.lang.String url,
                                     java.util.Properties defaults)
                              throws java.sql.SQLException
Throws:
java.sql.SQLException

port

public int port(java.util.Properties props)
Returns the port number property

Parameters:
props - the properties to get the port number from
Returns:
the port number

property

public java.lang.String property(java.lang.String name,
                                 java.util.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.