|
SPT RWT Application API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sptci.rwt.AbstractQueryExecutor
com.sptci.rwt.BatchQueryExecutor
public class BatchQueryExecutor
A utility class to execute SQL statements (single or batch).
© Copyright 2007 Sans Pareil Technologies, Inc.
| Field Summary | |
|---|---|
static String[] |
SPECIAL
An array database names that need special handling. |
| Fields inherited from class com.sptci.rwt.AbstractQueryExecutor |
|---|
manager |
| Constructor Summary | |
|---|---|
BatchQueryExecutor(ConnectionManager manager)
Create a new instance using the specified manager to fetch connections. |
|
| Method Summary | |
|---|---|
List<Rows> |
execute(String sql,
int... parameters)
Execute the specified statement(s) and return all the ResultSet and Statement.getUpdateCount()
values that result from executing the statement(s). |
private void |
execute(String sql,
List<Rows> list,
Connection connection,
int maxRows,
int columnLength)
Execute the specified SQL statement and fetch its associated result set or update count. |
org.apache.poi.hssf.usermodel.HSSFWorkbook |
export(String sql)
Execute the specified statement(s) and return a Excel workbook that represents all the data contained in the ResultSets obtained by executing the statement. |
private List<String> |
parseStatements(String sql)
Parse the specified SQL statement batch and extract individual statements from the batch. |
| Methods inherited from class com.sptci.rwt.AbstractQueryExecutor |
|---|
createStatement, getClobValue, processResultSet, processText, processUpdateCount |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String[] SPECIAL
| Constructor Detail |
|---|
public BatchQueryExecutor(ConnectionManager manager)
manager - The connection manager to use.| Method Detail |
|---|
public List<Rows> execute(String sql,
int... parameters)
throws SQLException
ResultSet and Statement.getUpdateCount()
values that result from executing the statement(s).
Note: Statement processing is handled differently for different database engines. PostgreSQL and Sybase (probably MS SQL Server) automatically support execution of a batch of statements and return multiple result sets and update counts corresponding to each statement included in the batch. Oracle and MySQL do not support this feature. For databases that do not support automatic batch execution, the SQL statement is parsed using a very simple rule - a semi-colon is treated as the delimiter for a statement; and executed individually. The Oracle default / character is used to denote the separator between individual statements. Needless to say this is a very serious shortcoming. You will not be able to execute complex statements such as procedure creation etc for these engines. The following shows simple syntax for delimited queries.
select * from table1 order by column1; / select * from table2;
sql - The statement(s) to be executed.parameters - Optioanl parameters to control the result set size. The
following parameters are supported:
maxRows The maximum number of rows to retrieve.
Specify 0 for no restriction.maxColumnLength The maximum size of a column. Specify
0 for no restriction.Rows objects that represents all
the ResultSet and Statement.getUpdateCount()s generated by executing the
statement(s).
SQLException - If errors are encountered while executing the
statement(s).parseStatements(java.lang.String),
execute( String, List, Connection, int, int )
public org.apache.poi.hssf.usermodel.HSSFWorkbook export(String sql)
throws SQLException
ResultSets obtained by executing the statement.
sql - The statement to be executed.
SQLException - If errors are encountered while executing the
statement.execute(java.lang.String, int...)
private void execute(String sql,
List<Rows> list,
Connection connection,
int maxRows,
int columnLength)
throws SQLException
sql - The SQL statement to execute.list - The list to which the results are to be added.connection - The database connection to use.maxRows - The maximum number of rows to fetch.columnLength - The maximum size for the data in a column.
SQLException - If errors are encountered while executing the query.AbstractQueryExecutor.createStatement(java.sql.Connection),
AbstractQueryExecutor.processResultSet(java.sql.Statement, int, int, int),
AbstractQueryExecutor.processUpdateCount(java.sql.Statement)private List<String> parseStatements(String sql)
Note This method currently supports Oracle style / separated commands. It is expected that MySQL users follow the same rule.
The parser code is taken from a post in the PostgreSQL forum. The original post can be viewed here.
sql - The batch of statements to be parsed.
|
SPT RWT Application API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||