|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfedora.utilities.DriverShim
public class DriverShim
Allows one to load a JDBC driver at runtime. java.sql.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. See the utility method, loadAndRegister and the command-line test below. Adapted from http://www.kfu.com/~nsayer/Java/dyn-jdbc.html
| Constructor Summary | |
|---|---|
DriverShim(java.sql.Driver d)
Constructs a DriverShim over the given driver in order to make it look like it came from this classloader. |
|
| Method Summary | |
|---|---|
boolean |
acceptsURL(java.lang.String u)
|
java.sql.Connection |
connect(java.lang.String u,
java.util.Properties p)
|
int |
getMajorVersion()
|
int |
getMinorVersion()
|
java.sql.DriverPropertyInfo[] |
getPropertyInfo(java.lang.String u,
java.util.Properties p)
|
boolean |
jdbcCompliant()
|
static void |
loadAndRegister(java.io.File driverJarFile,
java.lang.String driverClassName)
Loads the driver from the given jar file and registers it with the driver manager. |
static void |
loadAndRegister(java.net.URL driverURL,
java.lang.String driverClassName)
|
static void |
main(java.lang.String[] args)
Command-line test. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DriverShim(java.sql.Driver d)
| Method Detail |
|---|
public static final void loadAndRegister(java.io.File driverJarFile,
java.lang.String driverClassName)
throws java.lang.Exception
java.lang.Exception
public static final void loadAndRegister(java.net.URL driverURL,
java.lang.String driverClassName)
throws java.lang.Exception
java.lang.Exception
public boolean acceptsURL(java.lang.String u)
throws java.sql.SQLException
acceptsURL in interface java.sql.Driverjava.sql.SQLException
public java.sql.Connection connect(java.lang.String u,
java.util.Properties p)
throws java.sql.SQLException
connect in interface java.sql.Driverjava.sql.SQLExceptionpublic int getMajorVersion()
getMajorVersion in interface java.sql.Driverpublic int getMinorVersion()
getMinorVersion in interface java.sql.Driver
public java.sql.DriverPropertyInfo[] getPropertyInfo(java.lang.String u,
java.util.Properties p)
throws java.sql.SQLException
getPropertyInfo in interface java.sql.Driverjava.sql.SQLExceptionpublic boolean jdbcCompliant()
jdbcCompliant in interface java.sql.Driver
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||