|
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.jndi.ConnectionPool
public final class ConnectionPool
ConnectionPool is designed to ease the burden of establishing pooled connections within Servlets or JSP pages. It
supports many common functions for connecting to and verifying the connections to a given database. It is intended
for use with Oracle databases using the Oracle supplied JDBC drivers. Further, it is intended to work with JNDI
pooled connection resources.
A typical usage would be from within a JSP page such as this:
ConnectionPoolInterface db = new ConnectionPool("test").getConnectionPoolInterface();
#Microdeveloper development database
test.JNDI=test
#default test user
test.User=scott
#Scott's password
test.Pw=Rq2lKFXWb2c\=
#Driver
test.Driver=oracle.jdbc.driver.OracleDriver
#URL
test.Url=jdbc\:oracle\:thin\:@oracle.microdeveloper.com\:1521\:test
DesEncrypter
,
Connector
Field Summary | |
---|---|
static String |
ERR_CON
The constant in Connector that indicates that the connection to the database could not be opened. |
static String |
ERR_CTX
The constant in Connector that indicates the JNDI context was not found. |
static String |
ERR_DS
The constant in Connector that indicates the JNDI datasource was not found. |
static String |
ERR_NC
The constant in Connector that indicates that an operation was attempted on a closed or non-existant connection. |
static String |
ERR_OPN
The constant in Connector that indicates that an attempt was made to open a connection that was already open. |
static int |
ERRTYPE
|
static int |
MYSQLTYPE
|
static int |
ORACLETYPE
|
static int |
OTHERTYPE
|
Constructor Summary | |
---|---|
ConnectionPool()
Create a new instance of ConnectionPool. |
|
ConnectionPool(String dbAlias)
Create a new instance of ConnectionPool and connects to the given database. |
|
ConnectionPool(String dbAlias,
String name,
String pw)
Create a new instance of Connection pool and connects to the given database using username and password. |
Method Summary | |
---|---|
void |
close()
Closes the current pooled connection. |
void |
connect()
Opens the connection to the database using the established properties. |
void |
connect(String dbAlias)
Connects to the given database. |
void |
connect(String dbAlias,
String name,
String pw)
Open the connection to database using name and password given. |
void |
disconnect()
Closes the current pooled connection. |
String |
generateEncryptedPassword(String dbAlias,
String name,
String password)
Generates a new encrypted password and returns the result. |
Connection |
getConnection()
Returns the active java.sql.Connection object. |
ConnectionPoolInterface |
getConnectionPoolInterface()
Obtain the interface to the ConnectionPool |
String |
getDb()
Returns the currently established database name |
String |
getDbAlias()
Returns the currently established database alias |
String |
getDriver()
Returns the driver currently in effect from the dbnames file. |
String |
getJNDIDbFromAlias(String dbAlias)
Returns the associated JNDI database name for the given alias name |
String |
getPassword()
Returns the encrypted password for the current user |
String |
getSid()
Returns the optional established sid for Oracle databases. |
String |
getUrl()
Returns the URL to the database connection from the dbnames file. |
String |
getUsername()
Returns the current username for the ConnectionPool |
boolean |
isOpen()
Determines if the connection is open or not. |
void |
open()
Opens the connection to the database using the established properties. |
void |
open(String dbAlias)
Open the connection to database |
void |
open(String dbAlias,
String name,
String pw)
Open the connection to database using name and password given |
void |
printEncryptedPassword(String dbAlias,
String username,
String password)
Generates a new encrypted password and outputs the result to the console. |
boolean |
setDb(String dbAlias)
Sets the name of the database to use for subsequent connections. |
boolean |
setDbAlias(String dbAlias)
Sets the name of the database to use for subsequent connections. |
void |
setDbNamesFile(String value)
Set the name and path of the database name lookup file. |
void |
setPassword(String pw)
Sets the password for the ConnectionPool and subsequent connections. |
void |
setSid(String s)
Sets the Oracle Sid variable but has no effect on the connection. |
void |
setUsername(String name)
Sets the username for the ConnectionPool and subsequent connections. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ERR_CON
public static final String ERR_DS
public static final String ERR_CTX
public static final String ERR_NC
public static final String ERR_OPN
public static final int ORACLETYPE
public static final int MYSQLTYPE
public static final int OTHERTYPE
public static final int ERRTYPE
Constructor Detail |
---|
public ConnectionPool()
public ConnectionPool(String dbAlias) throws SQLException, NamingException
dbAlias
- the alias name of the database from the database properties file
SQLException
NamingException
public ConnectionPool(String dbAlias, String name, String pw) throws SQLException, NamingException
dbAlias
- the alias name of the database from the database properties filename
- database usernamepw
- password for the given username
SQLException
NamingException
Method Detail |
---|
public ConnectionPoolInterface getConnectionPoolInterface()
public void open(String dbAlias) throws SQLException, NamingException
dbAlias
- the alias name of the database from the database properties file
SQLException
- thrown if an error occurs while connecting to the database
NamingException
- thrown if an error occurs while attempting to read the parameters for the databaseopen()
,
(String, String, String)
,
(String)
,
connect()
public void open(String dbAlias, String name, String pw) throws SQLException, NamingException
dbAlias
- the alias name of the database from the database properties filename
- username to connect aspw
- password for the given name
SQLException
- thrown if an error occurs while connecting to the database
NamingException
- thrown if an error occurs while attempting to read the parameters for the databaseopen()
,
(String, String, String)
,
(String)
,
connect()
public void open() throws SQLException, NamingException
SQLException
- thrown if an error occurs while connecting to the database
NamingException
- thrown if an error occurs while attempting to read the parameters for the databaseconnect()
,
(String, String, String)
,
(String)
,
open(String)
public void setDbNamesFile(String value)
value
- the relative path the file (must be readable by server process)public String getUsername()
public String getPassword()
public String getSid()
public String getDriver()
public String getUrl()
public void setUsername(String name)
name
- database usernamepublic void setPassword(String pw)
pw
- clear text password for the current userpublic void setSid(String s)
s
- SID to set for this connectionpublic boolean setDb(String dbAlias)
dbAlias
- database alias name from the dbnames properties file.
setDbAlias(String)
public boolean setDbAlias(String dbAlias)
dbAlias
- the database name alias to be looked up in the properties file.
setDb(String)
public String getDb()
public String getDbAlias()
public String getJNDIDbFromAlias(String dbAlias)
dbAlias
- alias name of the database to lookup
public boolean isOpen()
public void close()
disconnect()
public void disconnect()
close()
public void printEncryptedPassword(String dbAlias, String username, String password)
username
- name of the user account to be stored or setpassword
- associated to the user that will be encrypteddbAlias
- alias to associate with this passwordgenerateEncryptedPassword(String,String,String)
public String generateEncryptedPassword(String dbAlias, String name, String password)
name
- name of the user account to be stored or setpassword
- associated to the user that will be encrypteddbAlias
- alias to associate with this passwordgenerateEncryptedPassword(String,String,String)
public void connect(String dbAlias) throws SQLException, NamingException
dbAlias
- alias name of the database to connect to
SQLException
NamingException
public void connect(String dbAlias, String name, String pw) throws SQLException, NamingException
dbAlias
- the alias name of the database from the database properties filename
- username to connect aspw
- password for the given name
SQLException
NamingException
public void connect() throws SQLException, NamingException
SQLException
- thrown if an error occurs while connecting to the database
NamingException
- thrown if an error occurs while attempting to read the parameters for the databaseopen()
,
(String, String, String)
,
(String)
,
open(String)
public Connection getConnection()
|
MDi JLib 1.7.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |