org.enableit.db
Class DatabaseProxy

java.lang.Object
  |
  +--org.enableit.db.DatabaseProxy
Direct Known Subclasses:
GenericDBProxy

public class DatabaseProxy
extends java.lang.Object

Proxy class to wrap database access in a simple form. The user is required to provide their own Connection

Author:
__AUTHOR__

Field Summary
static java.lang.String ABOUT
          CVS info about this class and its current version
static int LIST
          Valid Object type for result set returns
protected static org.apache.log4j.Category logger
          The Log4J Category doing the logging.
static int SQL_RESULT_SET
          Valid Object type for result set returns.
 
Constructor Summary
DatabaseProxy()
           
 
Method Summary
static int executeDmlProcedure(java.sql.Connection conn, java.lang.String sp, java.util.List parms)
          Execute the supplied stored procedure against the supplied database connection.
static java.util.ArrayList executeQuery(java.sql.Connection conn, java.lang.String sql)
          Execute the supplied SQL query against the supplied database connection.
static java.lang.Object executeQuery(java.sql.Connection conn, java.lang.String sql, int returnType)
          Deprecated. 
use executeQuery(conn:Connection, sql:String): java.util.ArrayList instead
static java.util.List executeQuery(java.sql.Connection conn, java.lang.String sql, java.util.List parms)
          Execute the supplied SQL query against the supplied database connection.
static java.lang.Object executeQueryProcedure(java.sql.Connection conn, java.lang.String sp, java.util.List parms, int returnType)
          Execute the supplied stored procedure against the supplied database connection.
static int executeUpdate(java.sql.Connection conn, java.lang.String sql)
          Execute the supplied SQL update query against a the supplied database connection.
static int executeUpdate(java.sql.Connection conn, java.lang.String sql, java.util.List parms)
          Execute the supplied SQL update statement against a the supplied database connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LIST

public static final int LIST
Valid Object type for result set returns

See Also:
Constant Field Values

SQL_RESULT_SET

public static final int SQL_RESULT_SET
Valid Object type for result set returns. When returning references to a java.sql.ResultSet the developer must take care to ensure that the reference and the Connection that created it are correctly closed to avoid a memory leak.

See Also:
Constant Field Values

logger

protected static org.apache.log4j.Category logger
The Log4J Category doing the logging. Same Category is used throughout the library.


ABOUT

public static final java.lang.String ABOUT
CVS info about this class and its current version

See Also:
Constant Field Values
Constructor Detail

DatabaseProxy

public DatabaseProxy()
Method Detail

executeQuery

public static java.util.ArrayList executeQuery(java.sql.Connection conn,
                                               java.lang.String sql)
                                        throws DBException
Execute the supplied SQL query against the supplied database connection.

Parameters:
conn - The database connection to use
sql - The SQL query to execute
Returns:
The SQL results stored as an java.util.ArrayList, each element of which is a java.util.TreeMap holding a single row of results
Throws:
DBException - If execution of the query failed.

executeQuery

public static java.util.List executeQuery(java.sql.Connection conn,
                                          java.lang.String sql,
                                          java.util.List parms)
                                   throws DBException
Execute the supplied SQL query against the supplied database connection.

Parameters:
conn - The database connection to use
sql - The SQL query to execute
parms - List containing parameters to insert in the sql statement.
Returns:
The SQL results stored as an java.util.ArrayList, each element of which is a java.util.TreeMap holding a single row of results
Throws:
DBException - If execution of the query failed.

executeQuery

public static java.lang.Object executeQuery(java.sql.Connection conn,
                                            java.lang.String sql,
                                            int returnType)
                                     throws DBException
Deprecated. 
use executeQuery(conn:Connection, sql:String): java.util.ArrayList instead

Execute the supplied SQL query against the supplied database connection.

Parameters:
conn - The database connection to use
sql - The SQL query to execute
returnType - The object type to convert the SQL results into
Returns:
The SQL results as the object type requested
Throws:
DBException - If execution of the query failed.

executeUpdate

public static int executeUpdate(java.sql.Connection conn,
                                java.lang.String sql)
                         throws DBException
Execute the supplied SQL update query against a the supplied database connection.

Parameters:
sql - The SQL update to execute
conn - The database connection to use
Returns:
The number of rows affected by the update.
Throws:
DBException - If execution of the update failed.

executeUpdate

public static int executeUpdate(java.sql.Connection conn,
                                java.lang.String sql,
                                java.util.List parms)
                         throws java.sql.SQLException,
                                DBException
Execute the supplied SQL update statement against a the supplied database connection.

This is preferred over executeUpdate(Connection, String) when parameters exist as it provides better handling of data types and may be significantly faster on some RDBMS (e.g. Oracle) as it permits caching of the parameterised PreparedStatement.

Parameters:
conn - The database connection to use
sql - The SQL update to execute with parameters represented by ?
parms - List containing parameters to insert in the sql statement
Returns:
The number of rows affected by the update.
Throws:
DBException - If execution of the update failed.
java.sql.SQLException

executeDmlProcedure

public static int executeDmlProcedure(java.sql.Connection conn,
                                      java.lang.String sp,
                                      java.util.List parms)
                               throws DBException
Execute the supplied stored procedure against the supplied database connection.

Parameters:
conn - The database connection to use
sp - A string containing the stored procedure name
parms - A java.util.List of String parameters for the stored procedure
Returns:
The number of rows affected by the stored procedure executed
Throws:
DBException - If execution of the stored procedure failed.

executeQueryProcedure

public static java.lang.Object executeQueryProcedure(java.sql.Connection conn,
                                                     java.lang.String sp,
                                                     java.util.List parms,
                                                     int returnType)
                                              throws DBException
Execute the supplied stored procedure against the supplied database connection.

Parameters:
conn - The database connection to use
sp - A string containing the stored procedure name
parms - A java.util.List of String parameters for the stored procedure
returnType - One of the defined return types defined as constants within this class.
Returns:
java.lang.Object containing any rows found. The Object type is defined by the return type parameter
Throws:
DBException - If execution of the stored procedure failed.


Copyright © 1999-2004 enableIT.org. All Rights Reserved.