Jboss hosting - JavaSercer Pages Example 17.15. The DBTag’s doAfterBody( )
JavaSercer Pages Example 17.15. The DBTag’s doAfterBody( ) Method public int doAfterBody( ) throws JspException { sqlValue = bodyContent.getString( ); return SKIP_BODY; } The SQL statement may contain question marks as placeholders for values set by nested value actions. As you will see later, the value actions create the appropriate Value subclass and call the DBTag ’s addValue( ) method, shown in Example 17.16. Example 17.16. The DBTag’s addValue( ) Method public void addValue(Value value) { if (values == null) { values = new Vector( ); } values.addElement(value); } This method creates a Vector to hold all values the first time it’s called, and then adds the Value object to the Vector. When called by subsequent value action tag handlers, the Value objects are simply added to the list. The real processing happens in the doEndTag( ) method, shown in Example 17.17. This method is called by the container when the action element’s body has been processed and the end tag is encountered. Example 17.17. The DBTag’s doEndTag( ) Method public int doEndTag( ) throws JspException { Connection conn = getConnection( ); sqlCommandBean.setConnection(conn); sqlCommandBean.setSqlValue(sqlValue); sqlCommandBean.setValues(values); Object result = null; try { result = execute(sqlCommandBean); } catch (SQLException e) { … } catch (UnsupportedTypeException e) { … } finally { … } // Save the result with the specified id in the specified scope if (id != null) { pageContext.setAttribute(id, result, scope); } return EVAL_PAGE; } The private getConnection( ) method is used to get a Connection. The Connection is retrieved either from the DataSource specified by the dataSource attribute value for the
Hint: This post is supported by Gama web hosting php mysql provider