Top Description Inners Fields Constructors Methods
org.hsqldb.jdbc

public Class JDBCDriver

extends Object
implements Driver
Class Inheritance
All Implemented Interfaces
java.sql.Driver
Known Direct Subclasses
org.hsqldb.jdbcDriver
Imports
java.sql.Connection, .Driver, .DriverManager, .DriverPropertyInfo, .SQLException, .DriverAction, .SQLFeatureNotSupportedException, java.util.Properties, org.hsqldb.DatabaseURL, org.hsqldb.error.ErrorCode, org.hsqldb.persist.HsqlDatabaseProperties, .HsqlProperties

The interface that every driver class must implement.

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 calling:

Class.forName("foo.bah.Driver")

A JDBC driver may create a DriverAction implementation in order to receive notifications when DriverManager#deregisterDriver has been called.

HSQLDB-Specific Information:

When the HSQL Database Engine Driver class is loaded, it creates an instance of itself and register it with the DriverManager. This means that a user can load and register the HSQL Database Engine driver by calling:
 Class.forName("org.hsqldb.jdbc.JDBCDriver")
 
For detailed information about how to obtain HSQLDB JDBC Connections, please see JDBCConnection.
JDBC 4.0 notes:

Starting with JDBC 4.0 (JDK 1.6), the DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. When built under a Java runtime that supports JDBC 4.0, HSQLDB distribution jars containing the Driver implementation also include the file META-INF/services/java.sql.Driver. This file contains the fully qualified class name ('org.hsqldb.jdbc.JDBCDriver') of the HSQLDB implementation of java.sql.Driver.

Hence, under JDBC 4.0 or greater, applications no longer need to explicitly load the HSQLDB JDBC driver using Class.forName(). Of course, existing programs which do load JDBC drivers using Class.forName() will continue to work without modification.

JDBC 4.2 methods added in Java 8 are generally supported.

Authors
Campbell Burnet (campbell-burnet@users dot sourceforge.net), Fred Toussi (fredt@users dot sourceforge.net)
Since
JDK 1.1, HSQLDB 1.9.0
Version
2.7.3
See Also
java.sql.DriverManager, java.sql.Connection, java.sql.DriverAction

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final String
conn_loginTimeout

name of loginTimeout property, can not change

public static final JDBCDriver
public final ThreadLocal<JDBCConnection>
threadConnection

As a separate instance of this class is registered with DriverManager for each class loader, the threadConnection is not declared as static.

Constructor Summary

AccessConstructor and Description
public
JDBCDriver()

Default constructor

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this driver understands the given URL; false otherwise null
acceptsURL
(String
the URL of the database
url
)

Implements java.sql.Driver.acceptsURL.

Retrieves whether the driver thinks that it can open a connection to the given URL.

public Connection

Returns:

a Connection object that represents a connection to the URL
connect
(String
the URL of the database to which to connect
url
,
Properties
a list of arbitrary string tag/value pairs as connection arguments. Normally at least a "user" and "password" property should be included.
info
)

Implements java.sql.Driver.connect.

Attempts to make a database connection to the given URL.

public static Connection

Returns:

a Connection object that represents a connection to the URL
getConnection
(String
the URL of the database to which to connect
url
,
Properties
a list of arbitrary string tag/value pairs as connection arguments including at least at a "user" and a "password" property
info
)

The static equivalent of the connect(String,Properties) method.

public int

Returns:

this driver's major version number
getMajorVersion
()

Implements java.sql.Driver.getMajorVersion.

Retrieves the driver's major version number.

public int

Returns:

this driver's minor version number
getMinorVersion
()

Implements java.sql.Driver.getMinorVersion.

Gets the driver's minor version number.

public Logger

Returns:

the parent Logger for this driver
getParentLogger
()

Implements java.sql.Driver.getParentLogger.

Return the parent Logger of all the Loggers used by this driver.

public DriverPropertyInfo[]

Returns:

an array of DriverPropertyInfo objects describing possible properties. This array may be an empty array if no properties are required.
getPropertyInfo
(String
the URL of the database to which to connect
url
,
Properties
a proposed list of tag/value pairs that will be sent on connect open
info
)

Implements java.sql.Driver.getPropertyInfo.

Gets information about the possible properties for this driver.

public boolean

Returns:

true if this driver is JDBC Compliant; false otherwise
jdbcCompliant
()

Implements java.sql.Driver.jdbcCompliant.

Reports whether this driver is a genuine JDBC Compliant driver.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conn_loginTimeoutback to summary
pack-priv static final String conn_loginTimeout

name of loginTimeout property, can not change

driverInstanceback to summary
public static final JDBCDriver driverInstance
threadConnectionback to summary
public final ThreadLocal<JDBCConnection> threadConnection

As a separate instance of this class is registered with DriverManager for each class loader, the threadConnection is not declared as static. The registered instance is kept to allow access to its threadConnection.

Constructor Detail

JDBCDriverback to summary
public JDBCDriver()

Default constructor

Method Detail

acceptsURLback to summary
public boolean acceptsURL(String url)

Implements java.sql.Driver.acceptsURL.

Retrieves whether the driver thinks that it can open a connection to the given URL. Typically drivers will return true if they understand the sub-protocol specified in the URL and false if they do not.

Parameters
url:String

the URL of the database

Returns:boolean

true if this driver understands the given URL; false otherwise null

connectback to summary
public Connection connect(String url, Properties info) throws SQLException

Implements java.sql.Driver.connect.

Attempts 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 driver manager is asked to connect to a given URL it passes the URL to each loaded driver in turn.

The driver should throw 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. Normally at least "user" and "password" properties should be included in the Properties object.

Note

If a property is specified as part of the url and is also specified in the Properties object, it is implementation-defined as to which value will take precedence. For maximum portability, an application should only specify a property once.

HSQLDB-Specific Information:

For the HSQL Database Engine, at least "user" and "password" properties should be included in the Properties.

From version 1.7.1, two optional properties are supported:

  • get_column_name (default true) - if set to false, a ResultSetMetaData.getColumnName() call will return the user defined label (getColumnLabel()) instead of the column name.
    This property is available in order to achieve compatibility with certain non-HSQLDB JDBC driver implementations.
  • strict_md if set to true, some ResultSetMetaData methods return more strict values for compatibility reasons.

From version 1.8.0.x, strict_md is deprecated (ignored) because metadata reporting is always strict (JDBC-compliant), and three new optional properties are supported:

  • ifexits (default false) - when true, an exception is raised when attempting to connect to an in-process file: or mem: scheme database instance if it has not yet been created. When false, an in-process file: or mem: scheme database instance is created automatically if it has not yet been created. This property does not apply to requests for network or res: (i.e. files_in_jar) scheme connections.
  • shutdown (default false) - when true, the the target database mimics the behaviour of 1.7.1 and older versions. When the last connection to a database is closed, the database is automatically shut down. The property takes effect only when the first connection is made to the database. This means the connection that opens the database. It has no effect if used with subsequent, simultaneous connections.
    This command has two uses. One is for test suites, where connections to the database are made from one JVM context, immediately followed by another context. The other use is for applications where it is not easy to configure the environment to shutdown the database. Examples reported by users include web application servers, where the closing of the last connection coincides with the web application being shut down.
  • default_schema - backwards compatibility feature. To be used for clients written before HSQLDB schema support. Denotes whether to use the default schema when a schema qualifier is not included in a database object's SQL identifier character sequence. Also affects the semantics of DatabaseMetaData calls that supply null-valued schemaNamePattern parameter values.
Parameters
url:String

the URL of the database to which to connect

info:Properties

a list of arbitrary string tag/value pairs as connection arguments. Normally at least a "user" and "password" property should be included.

Returns:Connection

a Connection object that represents a connection to the URL

Exceptions
SQLException:
if a database access error occurs or the url is null
getConnectionback to summary
public static Connection getConnection(String url, Properties info) throws SQLException

The static equivalent of the connect(String,Properties) method.

Parameters
url:String

the URL of the database to which to connect

info:Properties

a list of arbitrary string tag/value pairs as connection arguments including at least at a "user" and a "password" property

Returns:Connection

a Connection object that represents a connection to the URL

Annotations
@SuppressWarnings:deprecation
Exceptions
SQLException:
if a database access error occurs
getMajorVersionback to summary
public int getMajorVersion()

Implements java.sql.Driver.getMajorVersion.

Retrieves the driver's major version number. Initially this should be 1.

Returns:int

this driver's major version number

getMinorVersionback to summary
public int getMinorVersion()

Implements java.sql.Driver.getMinorVersion.

Gets the driver's minor version number. Initially this should be 0.

Returns:int

this driver's minor version number

getParentLoggerback to summary
public Logger getParentLogger() throws SQLFeatureNotSupportedException

Implements java.sql.Driver.getParentLogger.

Return the parent Logger of all the Loggers used by this driver. This should be the Logger farthest from the root Logger that is still an ancestor of all of the Loggers used by this driver. Configuring this Logger will affect all of the log messages generated by the driver. In the worst case, this may be the root Logger.

Returns:Logger

the parent Logger for this driver

Exceptions
SQLFeatureNotSupportedException:
if the driver does not use java.util.logging.
Since
JDK 1.7, HSQLDB 2.0.1
getPropertyInfoback to summary
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)

Implements java.sql.Driver.getPropertyInfo.

Gets information about the possible properties for this driver.

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 though several calls to the getPropertyInfo method.

HSQLDB-Specific Information:

HSQLDB uses the values submitted in info to set the value for each DriverPropertyInfo object returned.

Only the connection properties are considered. General database properties are ignored.

Parameters
url:String

the URL of the database to which to connect

info:Properties

a proposed list of tag/value pairs that will be sent on connect open

Returns:DriverPropertyInfo[]

an array of DriverPropertyInfo objects describing possible properties. This array may be an empty array if no properties are required.

jdbcCompliantback to summary
public boolean jdbcCompliant()

Implements java.sql.Driver.jdbcCompliant.

Reports whether this 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. It is expected that JDBC compliant drivers will be available for all the major commercial databases.

This method is not intended to encourage the development of non-JDBC compliant drivers, but is a recognition of the fact that some vendors are interested in using the JDBC API and framework for lightweight databases that do not support full database functionality, or for special databases such as document information retrieval where a SQL implementation may not be feasible.

Returns:boolean

true if this driver is JDBC Compliant; false otherwise

org.hsqldb.jdbc back to summary

private Class JDBCDriver.EmptyDiverAction

extends Object
implements DriverAction
Class Inheritance
All Implemented Interfaces
java.sql.DriverAction

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
deregister()

Implements java.sql.DriverAction.deregister.

Method called by DriverManager#deregisterDriver(Driver) to notify the JDBC driver that it was de-registered.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EmptyDiverActionback to summary
private EmptyDiverAction()

Method Detail

deregisterback to summary
public void deregister()

Implements java.sql.DriverAction.deregister.

Doc from java.sql.DriverAction.deregister.

Method called by DriverManager#deregisterDriver(Driver) to notify the JDBC driver that it was de-registered.

The deregister method is intended only to be used by JDBC Drivers and not by applications. JDBC drivers are recommended to not implement DriverAction in a public class. If there are active connections to the database at the time that the deregister method is called, it is implementation specific as to whether the connections are closed or allowed to continue. Once this method is called, it is implementation specific as to whether the driver may limit the ability to create new connections to the database, invoke other Driver methods or throw a SQLException. Consult your JDBC driver's documentation for additional information on its behavior.