public void doTag(XMLOutput output) throws Exception {
try {
conn = getConnection();
}
catch (SQLException e) {
throw new JellyException(sql + ": " + e.getMessage(), e);
}
/*
* Use the SQL statement specified by the sql attribute, if any,
* otherwise use the body as the statement.
*/
String sqlStatement = null;
if (sql != null) {
sqlStatement = sql;
}
else {
sqlStatement = getBodyText();
}
if (sqlStatement == null || sqlStatement.trim().length() == 0) {
throw new JellyException(Resources.getMessage("SQL_NO_STATEMENT"));
}
int result = 0;
try {
if ( hasParameters() ) {
PreparedStatement ps = conn.prepareStatement(sqlStatement);
setParameters(ps);
result = ps.executeUpdate();
}
else {
Statement statement = conn.createStatement();
result = statement.executeUpdate(sqlStatement);
}
if (var != null) {
context.setVariable(var, new Integer(result));
}
}
catch (SQLException e) {
throw new JellyException(sqlStatement + ": " + e.getMessage(), e);
}
finally {
if (conn != null && !isPartOfTransaction) {
try {
conn.close();