|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sadun.util.sql.DynamicConnectionFactory
This class allows to load JDBC drivers by specifiying their location at runtime, and to successively obtain connections.
Note that method loadDriver(String)
must be used instead of
Class.forName, and one of the getConnection(String)
overloads to
obtain a connection.
Using DriverManager directly will result in a "No suitable driver".
Example code follows:
DynamicConnectionFactory factory = new DynamicConnectionFactory(); factory.addClassPathEntry(..class path of the jdbc driver(s)...); factory.loadDriver(..driver class name...); Connection conn = factory.getConnection(..jdbc URL...);
Constructor Summary | |
DynamicConnectionFactory()
Create a factory which uses the same class path as the system. |
Method Summary | |
void |
addClassPathEntry(java.lang.String entry)
Add a class path entry. |
java.sql.Connection |
getConnection(java.lang.String jdbcUrl)
Return a connection by using the given jdbc URL (as DriverManager) |
java.sql.Connection |
getConnection(java.lang.String jdbcUrl,
java.util.Properties p)
Return a connection by using the given jdbcURL and properties (as DriverManager) |
java.sql.Connection |
getConnection(java.lang.String jdbcUrl,
java.lang.String user,
java.lang.String pwd)
Return a connection by using the given jdbcURL and username/password (as DriverManager) |
java.lang.Class |
loadDriver(java.lang.String driverClassName)
Load a JDBC driver dynamically. |
void |
setClassPath(java.lang.String cp)
Set the class path. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DynamicConnectionFactory()
addClassPathEntry(String)
can be successively used to extend the class path}.
Method Detail |
public void addClassPathEntry(java.lang.String entry)
entry
- the entry to addpublic void setClassPath(java.lang.String cp)
cp
- the class path to set.public java.lang.Class loadDriver(java.lang.String driverClassName) throws java.lang.ClassNotFoundException
driverClassName
- the name of the driver
java.lang.ClassNotFoundException
- if the driver class does not existpublic java.sql.Connection getConnection(java.lang.String jdbcUrl, java.util.Properties p) throws java.sql.SQLException
jdbcUrl
- the JDBC url to connect top
- the connection properties
java.sql.SQLException
- if a connection cannot be establishedpublic java.sql.Connection getConnection(java.lang.String jdbcUrl) throws java.sql.SQLException
jdbcUrl
- the JDBC url to connect to
java.sql.SQLException
- if a connection cannot be establishedpublic java.sql.Connection getConnection(java.lang.String jdbcUrl, java.lang.String user, java.lang.String pwd) throws java.sql.SQLException
jdbcUrl
- the JDBC url to connect touser
- the user
java.sql.SQLException
- if a connection cannot be established
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |