|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.aselect.system.db.SQLDatabaseConnector
public class SQLDatabaseConnector
SQL database connection functionality.
Description: br> Database connection and query functionality for an
SQL database (e.g. MySQL).
If you are using transactions safe tables (like InnoDB, BDB) you can use the
startTransaction(Statement)
,commitTransaction(Statement)
,
and rollbackTransaction(Statement)
methods to start, commit and
rollback transactions.
Concurrency issues:
The functionality of this class is threadsafe. All critical methods are
synchronized.
Constructor Summary | |
---|---|
SQLDatabaseConnector(java.lang.String sDriverName,
java.lang.String sUser,
java.lang.String sPassword,
java.lang.String sURL,
SystemLogger systemLogger)
Create a new instance. |
Method Summary | |
---|---|
void |
commitTransaction(java.sql.Statement oStmt)
Excute the "COMMIT" command. |
java.sql.Statement |
connect()
Connect to the database. |
boolean |
disconnect(java.sql.Statement oStmt)
Close the database connection. |
java.sql.ResultSet |
executeQuery(java.sql.Statement oStmt,
java.lang.String sQuery)
Execute a SQL query. |
int |
executeUpdate(java.sql.Statement oStmt,
java.lang.String sQuery)
Execute a SQL update query. |
java.lang.String |
getDatabaseUrl()
Returns the database URL. |
void |
rollbackTransaction(java.sql.Statement oStmt)
Excute the "ROLLBACK" command. |
void |
startTransaction(java.sql.Statement oStmt)
Execute the "BEGIN" command. |
void |
updateCount(boolean bConnect)
Update connection counter. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SQLDatabaseConnector(java.lang.String sDriverName, java.lang.String sUser, java.lang.String sPassword, java.lang.String sURL, SystemLogger systemLogger) throws ASelectDatabaseException
SQLDatabaseConnector
:
systemLogger
is an initialized
SystemLogger
.
sDriverName != null
sUser != null
sPassword != null
sURL != null
sDriverName
- The database driver name.sUser
- The database user.sPassword
- The database password.sURL
- The database URL.systemLogger
- The system logger.
ASelectDatabaseException
- If database driver initialization fails.Method Detail |
---|
public void updateCount(boolean bConnect)
bConnect
- If true the number of open connections is increased, otherwise
it is decreased.public java.sql.Statement connect()
Connection
if connection with database
does not exist yetStatement
Statement
.public boolean disconnect(java.sql.Statement oStmt)
oStmt
should be retrieved by calling connect()
oStmt
- The statement that is to be closed.
public java.sql.ResultSet executeQuery(java.sql.Statement oStmt, java.lang.String sQuery) throws ASelectDatabaseException
Statement
to execute the given query. Statement
.oStmt
should be retrieved by calling
connect()
sQuery
should be a correct SQL query
oStmt
- The statement that is used for rhe execution of the query.sQuery
- The query that is to be executed.
ASelectDatabaseException
- If execution fails.public int executeUpdate(java.sql.Statement oStmt, java.lang.String sQuery) throws ASelectDatabaseException
Statement
to execute the given query. The
query updates data in the database. Statement
.oStmt
should be retrieved by calling
connect()
sQuery
should be a correct SQL query
oStmt
- The statement that is used for the execution of the query.sQuery
- The query that is to be executed.
ASelectDatabaseException
- If update fails.Statement.executeUpdate(java.lang.String)
public void startTransaction(java.sql.Statement oStmt) throws ASelectDatabaseException
oStmt
should be retrieved by calling connect()
oStmt
- The statement that is used for the execution.
ASelectDatabaseException
- If transaction could not be started.public void rollbackTransaction(java.sql.Statement oStmt) throws ASelectDatabaseException
oStmt
should be retrieved by calling
connect()
startTransaction(Statement)
should be executed before
calling this method
oStmt
- The statement that is used for the execution.
ASelectDatabaseException
- If transaction could not be rolled back.public void commitTransaction(java.sql.Statement oStmt) throws ASelectDatabaseException
oStmt
should be retrieved by calling
connect()
startTransaction(Statement)
should be executed
oStmt
- The statement that is used for the execution.
ASelectDatabaseException
- If transaction could not be committed.public java.lang.String getDatabaseUrl()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |