else if (obj instanceof String) {
try {
maxRows = Integer.parseInt((String) obj);
}
catch (NumberFormatException nfe) {
throw new JellyException(
Resources.getMessage("SQL_MAXROWS_PARSE_ERROR", (String) obj),
nfe);
}
}
else {
throw new JellyException(Resources.getMessage("SQL_MAXROWS_INVALID"));
}
}
}
Result result = null;
String sqlStatement = null;
log.debug( "About to lookup connection" );
try {
conn = getConnection();
/*
* Use the SQL statement specified by the sql attribute, if any,
* otherwise use the body as the statement.
*/
if (sql != null) {
sqlStatement = sql;
}
else {
sqlStatement = getBodyText();
}
if (sqlStatement == null || sqlStatement.trim().length() == 0) {
throw new JellyException(Resources.getMessage("SQL_NO_STATEMENT"));
}
/*
* We shouldn't have a negative startRow or illegal maxrows
*/
if ((startRow < 0) || (maxRows < -1)) {
throw new JellyException(Resources.getMessage("PARAM_BAD_VALUE"));
}
/*
* Note! We must not use the setMaxRows() method on the
* the statement to limit the number of rows, since the
* Result factory must be able to figure out the correct
* value for isLimitedByMaxRows(); there's no way to check
* if it was from the ResultSet.
*/
if ( log.isDebugEnabled() ) {
log.debug( "About to execute query: " + sqlStatement );
}
ResultSet rs = null;
if ( hasParameters() ) {
PreparedStatement ps = conn.prepareStatement(sqlStatement);
setParameters(ps);
rs = ps.executeQuery();
}
else {
Statement statement = conn.createStatement();
rs = statement.executeQuery(sqlStatement);
}
result = new ResultImpl(rs, startRow, maxRows);
context.setVariable(var, result);
}
catch (SQLException e) {
throw new JellyException(sqlStatement + ": " + e.getMessage(), e);
}
finally {
if (conn != null && !isPartOfTransaction) {
try {
conn.close();