| [ Team LiB ] |
|
23.5 Integrating Custom Database ActionsThe JSTL database access actions look for the default values set by the configuration settings described in Tables Table 23-5 and Table 23-6.
The data-source setting can be set as a String in this format, in which optional parts are shown between brackets: url [, [driver] [, [user] [, [password]]] Commas separate the parts, so if the value for any part contains a comma, it must be escaped with a backslash. This type of value creates a simple DataSource without any pooling capabilities, and is intended only for prototype and low-end applications, as described in Chapter 12. It can also be set to a JNDI path for a DataSource made available by the container or to a DataSource created by custom code, such as a servlet or listener. These options are described in detail in Chapter 24. The maximum rows setting can be set as a String value for a context parameter or as an Integer by custom code. It can be used to prevent runaway queries, because it sets a limit for how many rows are retrieved for a query result. There are also two support classes related to the JSTL database actions. The javax.servlet.jsp.jstl.sql.SQLExcecutionTag interface is implemented by the tag handlers for both <sql:query> and <sql:update>. It provides one method that allows a nested custom action to add a value for a parameter placeholder in the SQL statement: public void addSQLParameter(Object value) The value must be of a type that is accepted for the corresponding column when set by calling java.sql.PreparedStatement.setObject(int index, Object value). The ResultSupport class provides methods for converting a JDBC ResultSet into a JSTL Result object, described in Chapter 12: public static Result toResult(java.sql.ResultSet rs) public static Result toResult(java.sql.ResultSet rs, int maxRows) I'll show you an example of how to use it in Chapter 24. |
| [ Team LiB ] |
|