Class DriverShim
- java.lang.Object
-
- org.fbsql.servlet.DriverShim
-
- All Implemented Interfaces:
java.sql.Driver
public class DriverShim extends java.lang.Object implements java.sql.Driver
Allows one to load a JDBC driver at runtime. Workaround which allows to use URLClassLoader for JDBC driver loading, because the DriverManager will refuse to use a driver not loaded by the system ClassLoader The workaround for this is to use a shim class that implements java.sql.Driver. This shim class will do nothing but call the methods of an instance of a JDBC driver that is loaded dynamically. This works because DriverShim is loaded by the system class loader, and DriverManager doesn't care that it invokes a class that wasn't. Note that we must perform the registration on the instance ourselves. Adapted from http://www.kfu.com/~nsayer/Java/dyn-jdbc.html
-
-
Field Summary
Fields Modifier and Type Field Description private java.sql.Driver
driver
The JDBC driver we're wrapping.
-
Constructor Summary
Constructors Constructor Description DriverShim(java.sql.Driver driver)
Constructs a DriverShim over the given driver in order to make it look like it came from this classloader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptsURL(java.lang.String jdbcUrl)
Retrieves whether the driver thinks that it can open a connection to the given URL.java.sql.Connection
connect(java.lang.String jdbcUrl, java.util.Properties properties)
int
getMajorVersion()
Retrieves the driver's major version number.int
getMinorVersion()
Gets the driver's minor version number.java.util.logging.Logger
getParentLogger()
Return the parent Logger of all the Loggers used by this driver.java.sql.DriverPropertyInfo[]
getPropertyInfo(java.lang.String jdbcUrl, java.util.Properties properties)
Gets information about the possible properties for this driver.boolean
jdbcCompliant()
Reports whether this driver is a genuine JDBC Compliant™ driver.
-
-
-
Field Detail
-
driver
private java.sql.Driver driver
The JDBC driver we're wrapping.
-
-
Constructor Detail
-
DriverShim
public DriverShim(java.sql.Driver driver)
Constructs a DriverShim over the given driver in order to make it look like it came from this classloader.- Parameters:
driver
- the JDBC driver we're wrapping
-
-
Method Detail
-
acceptsURL
public boolean acceptsURL(java.lang.String jdbcUrl) throws java.sql.SQLException
Retrieves whether the driver thinks that it can open a connection to the given URL. Typically drivers will returntrue
if they understand the sub-protocol specified in the URL andfalse
if they do not.- Specified by:
acceptsURL
in interfacejava.sql.Driver
- Parameters:
url
- the URL of the database- Returns:
true
if this driver understands the given URL;false
otherwise- Throws:
java.sql.SQLException
- if a database access error occurs or the url isnull
-
connect
public java.sql.Connection connect(java.lang.String jdbcUrl, java.util.Properties properties) throws java.sql.SQLException
- Specified by:
connect
in interfacejava.sql.Driver
- Throws:
java.sql.SQLException
-
getMajorVersion
public int getMajorVersion()
Retrieves the driver's major version number. Initially this should be 1.- Specified by:
getMajorVersion
in interfacejava.sql.Driver
- Returns:
- this driver's major version number
-
getMinorVersion
public int getMinorVersion()
Gets the driver's minor version number. Initially this should be 0.- Specified by:
getMinorVersion
in interfacejava.sql.Driver
- Returns:
- this driver's minor version number
-
getPropertyInfo
public java.sql.DriverPropertyInfo[] getPropertyInfo(java.lang.String jdbcUrl, java.util.Properties properties) throws java.sql.SQLException
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 thegetPropertyInfo
method.- Specified by:
getPropertyInfo
in interfacejava.sql.Driver
- Parameters:
url
- the URL of the database to which to connectinfo
- 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
-
jdbcCompliant
public boolean jdbcCompliant()
Reports whether this driver is a genuine JDBC Compliant™ driver. A driver may only reporttrue
here if it passes the JDBC compliance tests; otherwise it is required to returnfalse
.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.
- Specified by:
jdbcCompliant
in interfacejava.sql.Driver
- Returns:
true
if this driver is JDBC Compliant;false
otherwise
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
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.- Specified by:
getParentLogger
in interfacejava.sql.Driver
- Returns:
- the parent Logger for this driver
- Throws:
java.sql.SQLFeatureNotSupportedException
- if the driver does not usejava.util.logging
.- Since:
- 1.7
-
-