|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.sql.Connector
@ThirdParty(value="JDBC driver classes if used") public class Connector
The Connector class provides some simplified access to several database systems through convenient methods. Although the class doesn't require any additional driver software for compilation, certain methods may through SQLException if the specified driver is not present at the time.
ConnectorSettings,
JConnectionLogin| Nested Class Summary | |
|---|---|
static class |
Connector.DBType
supported database types transparently supported by the Connector class |
| Field Summary | |
|---|---|
protected String |
MYSQL_DRIVER_CLASS
|
static String |
ODBC_DRIVER
|
| Constructor Summary | |
|---|---|
Connector()
|
|
Connector(String propertiesPrefix)
|
|
| Method Summary | |
|---|---|
Connection |
createInstance(EventObject eo)
this implementation calls getConnectionFromSettings() |
Connection |
getAccessConnection(File msAccessFile)
|
Connection |
getAccessConnection(File msAccessFile,
String user,
String password,
boolean memoryOnly)
|
CipherKey |
getCipherKey()
|
Connection |
getConnection(Connector.DBType type,
String server,
int port,
String dbname,
String user,
String password)
returns a connection based on the information given. |
Connection |
getConnection(Connector.DBType type,
String server,
String dbname,
String user,
String password)
returns a connection based on the information given. |
Connection |
getConnectionFromProperties(String prefix,
Properties props)
this methods looks for the following property keys in the given properties from which it creates the connection (the given prefix will be prepended): cipherKey - if given, a CipherKey is used to try to decrypt user and password
The other settings are read according to getConnectionFromProperties(String, Properties, CipherKey)
#see getConnectionFromProperties(String, Properties, CipherKey) |
Connection |
getConnectionFromProperties(String prefix,
Properties props,
CipherKey key)
this methods looks for the following property keys in the given properties from which it creates the connection (the given prefix will be prepended): db.odbc - if given, a simple ODBC connection will be returned db.driver.class - if given (along with a url), the given class is dynamically loaded and used with the url (see below) db.driver.class.init - if true, a given driver class would be initialized while loading db.driver.url - if given (along with a class) this url is used to create the connection db.type - specifies the database type; corresponds to the Connector.DBType
db.server
db.port
db.name
db.user
db.password
db.ssl - specifies whether SSL is to be used
|
Connection |
getConnectionFromSettings()
|
Connection |
getConnectionFromSettings(String prefix)
|
Properties |
getConnectionProperties()
allows to specify further connection properties |
Connection |
getDerbyConnection(String dbName,
boolean createOption)
|
Connection |
getDerbyConnection(String hostName,
int port,
String dbName,
String user,
String password,
boolean createOption)
uses the embedded Apache Derby (JavaDB) driver by connecting to a running server |
Connection |
getDerbyConnection(String dbName,
String user,
String password,
boolean createOption)
uses the embedded Apache Derby (JavaDB) driver in a single-process mode |
Connection |
getDerbyConnection(String hostName,
String dbName,
String user,
String password,
boolean createOption)
|
Connection |
getFirebirdConnection(String server,
int port,
String dbFileName,
String user,
String password)
|
Connection |
getFirebirdConnection(String server,
String dbFileName)
|
Connection |
getFirebirdConnection(String server,
String dbFileName,
String user,
String password)
|
Processor<Connection,SQLException> |
getHandler()
|
Connection |
getHsqldbConnection(String host,
int port,
String dbName,
String login,
String password)
provides JDBC access through the Hsqldb driver (http://hsqldb.sourceforge.net/) |
Connection |
getHsqldbConnection(String dbName,
String login,
String password)
provides JDBC access through the Hsqldb driver (http://hsqldb.sourceforge.net/) |
Connection |
getHsqldbConnection(String host,
String dbName,
String login,
String password)
provides JDBC access through the Hsqldb driver (http://hsqldb.sourceforge.net/) |
Connection |
getHsqldbInMemory()
a special in-memory database using the HSQLDB driver |
Connection |
getMDBConnection(File mdbFile)
provides some simplified access to an existing Microsoft Access database through Sun's JDBC/ODBC bridge |
Connection |
getMDBConnection(File mdbFile,
File workGroupFile,
Properties props)
provides some simplified access to an existing Microsoft Access database through Sun's JDBC/ODBC bridge |
Connection |
getMDBConnection(File mdbFile,
File workGroupFile,
String user,
String password,
Properties props)
provides some simplified access to an existing Microsoft Access database through Sun's JDBC/ODBC bridge |
Connection |
getMDBConnection(File mdbFile,
Properties props)
provides some simplified access to an existing Microsoft Access database through Sun's JDBC/ODBC bridge |
Connection |
getMySQLConnection(String host,
int port,
String dbName,
String login,
String password)
provides simplified access to a MySQL database using MySQL Connector/J 3.1 |
Connection |
getMySQLConnection(String host,
String dbName,
String login,
String password)
uses the standard port 3306 |
Connection |
getODBCConnection(String dbName)
provides some simplified access to existing ODBC connections through Sun's JDBC/ODBC bridge |
Connection |
getODBCConnection(String dbName,
Properties props)
|
Connection |
getODBCConnection(String dbName,
String login,
String password)
provides some simplified access to existing ODBC connections through Sun's JDBC/ODBC bridge |
String |
getPropertiesPrefix()
|
Connection |
getSAPDBConnection(String host,
int port,
String dbName,
String user,
String password)
|
Connection |
getSAPDBConnection(String host,
String dbName,
String user,
String password)
|
Connection |
getSQLiteConnection(String dbname)
uses the JDBC driver from www.ch-werner.de/javasqlite |
Connection |
getSQLiteMemoryConnection()
|
Connection |
getSQLServerConnection(String host,
int port,
String dbName,
String login,
String password)
getSQLServerConnection() provides access to a Microsoft SQL-Server database. |
Connection |
getSQLServerConnection(String host,
String dbName,
String login,
String password)
|
String |
getSQLServerDriver()
|
protected Connection |
init(Connection con)
|
boolean |
isSQLiteFile(File file)
|
boolean |
isUseSSL()
|
Class<?> |
loadDriverClass(String driverClass,
boolean initNewInstance,
URL... driverJarUrls)
loads the given class and wraps occurring exceptions into an SQLException |
void |
setCipherKey(CipherKey cipherKey)
|
void |
setDerbySystemHome(String directory)
sets the system home directory to be used for the Apache Derby (JavaDB) database access |
void |
setHandler(Processor<Connection,SQLException> handler)
|
void |
setPropertiesPrefix(String propertiesPrefix)
|
void |
setSQLServerDriver(String driverClassName)
sets the name of the driver class to be used by getSQLServerConnection(). |
void |
setUseSSL(boolean flag)
|
void |
shutDownDerby(String dbName)
|
void |
shutDownDerby(String dbName,
String user,
String password)
shuts down the Apache Derby (JavaDB) database if the given dbName is null, all databases are shut down |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String ODBC_DRIVER
protected String MYSQL_DRIVER_CLASS
| Constructor Detail |
|---|
public Connector()
public Connector(String propertiesPrefix)
| Method Detail |
|---|
public Connection createInstance(EventObject eo)
throws Exception
getConnectionFromSettings()
createInstance in interface Factory<Connection>eo - the event that triggered this instance creation; normally, this method
should also cope with the event to be null.
Exceptionpublic boolean isUseSSL()
public void setUseSSL(boolean flag)
public Processor<Connection,SQLException> getHandler()
public void setHandler(Processor<Connection,SQLException> handler)
protected Connection init(Connection con)
throws SQLException
SQLExceptionpublic CipherKey getCipherKey()
public void setCipherKey(CipherKey cipherKey)
public String getPropertiesPrefix()
public void setPropertiesPrefix(String propertiesPrefix)
public Connection getConnectionFromSettings()
throws SQLException,
GeneralSecurityException
SQLException
GeneralSecurityException
public Connection getConnectionFromSettings(String prefix)
throws SQLException,
GeneralSecurityException
SQLException
GeneralSecurityExceptionSettings.getProperties()
public Connection getConnectionFromProperties(String prefix,
Properties props)
throws SQLException,
GeneralSecurityException
CipherKey is used to try to decrypt user and password
getConnectionFromProperties(String, Properties, CipherKey)
#see getConnectionFromProperties(String, Properties, CipherKey)
SQLException
GeneralSecurityException
public Connection getConnectionFromProperties(String prefix,
Properties props,
CipherKey key)
throws SQLException
Connector.DBType
key - if a key is given, user and password will go through a decryption attempt before use
SQLExceptiongetConnection(DBType, String, String, String, String)public Properties getConnectionProperties()
public Connection getConnection(Connector.DBType type,
String server,
String dbname,
String user,
String password)
throws SQLException
Connector.DBType.ODBC, the server parameter is ignored;
for Connector.DBType.SQLite, all but the dbname parameter are ignored.
SQLException
public Connection getConnection(Connector.DBType type,
String server,
int port,
String dbname,
String user,
String password)
throws SQLException
Connector.DBType.ODBC, the server parameter is ignored;
for Connector.DBType.SQLite, all but the dbname parameter are ignored.
SQLException
public Class<?> loadDriverClass(String driverClass,
boolean initNewInstance,
URL... driverJarUrls)
throws SQLException
driverClass - the name of the driver class to be loadedinitNewInstance - if true, a new instance is created of the given classdriverJarUrls - allows to specify external jar files that will be dynamically loaded
using a URLClassLoader
SQLExceptionDriverWrapper
public Connection getFirebirdConnection(String server,
String dbFileName)
throws SQLException
SQLException
public Connection getFirebirdConnection(String server,
String dbFileName,
String user,
String password)
throws SQLException
SQLException
public Connection getFirebirdConnection(String server,
int port,
String dbFileName,
String user,
String password)
throws SQLException
SQLException
public Connection getSAPDBConnection(String host,
String dbName,
String user,
String password)
throws SQLException
SQLException
public Connection getSAPDBConnection(String host,
int port,
String dbName,
String user,
String password)
throws SQLException
SQLException
public Connection getMySQLConnection(String host,
String dbName,
String login,
String password)
throws SQLException
SQLException
public Connection getMySQLConnection(String host,
int port,
String dbName,
String login,
String password)
throws SQLException
SQLException
public Connection getMDBConnection(File mdbFile)
throws SQLException
SQLException
public Connection getMDBConnection(File mdbFile,
Properties props)
throws SQLException
SQLException
public Connection getMDBConnection(File mdbFile,
File workGroupFile,
String user,
String password,
Properties props)
throws SQLException
SQLException
public Connection getMDBConnection(File mdbFile,
File workGroupFile,
Properties props)
throws SQLException
SQLException
public Connection getODBCConnection(String dbName)
throws SQLException
SQLException
public Connection getODBCConnection(String dbName,
Properties props)
throws SQLException
SQLException
public Connection getODBCConnection(String dbName,
String login,
String password)
throws SQLException
SQLExceptionpublic String getSQLServerDriver()
public void setSQLServerDriver(String driverClassName)
throws IllegalArgumentException
getSQLServerConnection().
Currently known drivers: com.microsoft.jdbc.sqlservernet.sourceforge.jtds.jdbc.Drivercom.microsoft.sqlserver.jdbc.SQLServerDriver
IllegalArgumentException - if the given driver name isn't known to this implementation
public Connection getSQLServerConnection(String host,
String dbName,
String login,
String password)
throws SQLException
SQLException
public Connection getSQLServerConnection(String host,
int port,
String dbName,
String login,
String password)
throws SQLException
SQLExceptionsetSQLServerDriver(String)
public Connection getHsqldbInMemory()
throws SQLException
SQLException
public Connection getHsqldbConnection(String host,
String dbName,
String login,
String password)
throws SQLException
SQLException
public Connection getHsqldbConnection(String host,
int port,
String dbName,
String login,
String password)
throws SQLException
SQLException
public Connection getHsqldbConnection(String dbName,
String login,
String password)
throws SQLException
dbName - the path and name of the database (example: /dir/db1)login - as a default, sa can be used for the system administrator
SQLExceptionpublic void setDerbySystemHome(String directory)
public void shutDownDerby(String dbName)
throws SQLException
SQLException
public void shutDownDerby(String dbName,
String user,
String password)
throws SQLException
SQLException
public Connection getDerbyConnection(String dbName,
boolean createOption)
throws SQLException
SQLException
public Connection getDerbyConnection(String dbName,
String user,
String password,
boolean createOption)
throws SQLException
SQLException
public Connection getDerbyConnection(String hostName,
String dbName,
String user,
String password,
boolean createOption)
throws SQLException
SQLException
public Connection getDerbyConnection(String hostName,
int port,
String dbName,
String user,
String password,
boolean createOption)
throws SQLException
SQLException
public Connection getSQLiteConnection(String dbname)
throws SQLException
SQLException
public Connection getSQLiteMemoryConnection()
throws SQLException
SQLException
public boolean isSQLiteFile(File file)
throws IOException
IOException
@ThirdParty(value="net.ucanaccess.jdbc.UcanaccessDriver")
public Connection getAccessConnection(File msAccessFile)
throws SQLException
SQLException
@ThirdParty(value="net.ucanaccess.jdbc.UcanaccessDriver")
public Connection getAccessConnection(File msAccessFile,
String user,
String password,
boolean memoryOnly)
throws SQLException
SQLException
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||