|
MDi JLib 1.7.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.microdeveloper.db.Connector
public class Connector
Connector for connecting to database source using a database names property file. Requires username, password, and database aliases for connection to the desired database. These may be set through property values, or direct calls
A typical usage would be
Connection conn = new Connector("myDb");this will take care of the driver, url, username, password, setup and connection in one simple step. Furthermore, the passwords are stored in an encrypted manner keeping your database keys in one place and keeping them secure.
v1.2 fixes failure to connect when instantiated
v1.1 adds new constructors that initializes the database target
v1.0 initial version
ConnectionPool
,
DesEncrypter
Constructor Summary | |
---|---|
Connector()
Constructor Connector creates an empty Connector without any established properties. |
|
Connector(String dbAlias)
Creates a new instance of Connector and connects to database dbName. |
|
Connector(String dbAlias,
String name,
String pw)
Creates a new instance of Connector and connects to the database using the parameters given. |
|
Connector(String driver,
String url,
String name,
String pw)
Creates a new instance of Connector and connects to the database using the parameters given. |
Method Summary | |
---|---|
void |
close()
Closes the database connection. |
Connection |
connect()
Method open opens the connection to the database using pre-established properties. |
void |
disconnect()
Closes the database connection. |
Connection |
getConnection()
Returns the current java.sql.Connection object. |
String |
getDb()
Deprecated. as of version 1.1, no longer necessary |
String |
getDbAlias()
Returns the database alias in effect |
String |
getDbDriver()
Returns the currently set driver |
String |
getDbUrl()
Returns the current database URL |
String |
getPassword()
Returns the currently set password for establishing new connections with. |
String |
getUsername()
Returns the currently set username for establishing new connections with |
boolean |
isComplete()
Determines if the necessary parameters are set to form a database connection with. |
boolean |
isOpen()
Method isOpen returns the open state of the connection. |
boolean |
setDb(String dbAlias)
Sets the current connection parameters to those specified by the given alias parameter in the properties file. |
boolean |
setDbAlias(String dbAlias)
Sets the current connection parameters to those specified by the given alias parameter in the properties file. |
void |
setDbDriver(String driver)
Sets the driver property to the String given. |
void |
setDbUrl(String url)
Sets the database URL property to the String given. |
void |
setPassword(String pw)
Sets the password for the current user. |
void |
setUsername(String name)
Sets the username property to the String given. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Connector()
Connector(String)
,
Connector(String,String,String)
,
Connector(String,String,String,String)
public Connector(String dbAlias)
dbAlias
- name of the database to establish a connection to.public Connector(String dbAlias, String name, String pw)
dbAlias
- the alias used in the dbnames.properties file (or designated file)name
- the name of the user to connect aspw
- the password for the user namepublic Connector(String driver, String url, String name, String pw)
driver
- the driver to use for the connectionurl
- the url to connect toname
- the name of the user to connect aspw
- the password for the user nameMethod Detail |
---|
public Connection connect() throws SQLException
SQLException
- if the connection cannot be established or any other connection error occurs
(e.g., bad database URL)setDb(dbName)
public Connection getConnection()
public String getDb()
public String getDbAlias()
public String getDbUrl()
public String getDbDriver()
public String getUsername()
public String getPassword()
DesEncrypter
public boolean isOpen()
public boolean isComplete()
public boolean setDbAlias(String dbAlias)
dbAlias
- the database name alias to be looked up in the properties file.
public boolean setDb(String dbAlias)
dbAlias
- the database name alias to be looked up in the properties file.
public void setDbUrl(String url)
url
- the fully qualified database URL (e.g., jdbc:oracle:thin:@host:1521:orcl)public void setDbDriver(String driver)
driver
- a fully qualified driver (e.g., oracle.jdbc.driver.OracleDriver)public void setUsername(String name)
name
- username to connect to the database aspublic void setPassword(String pw)
pw
- clear text password for the connectionpublic void disconnect()
public void close()
|
MDi JLib 1.7.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |