dbquery tag JSP syntax
Use the <tsx:dbquery> tag to establish a connection to a database, submit database queries, and return the results set.
The <tsx:dbquery> tag does the following...
- References a <tsc:dbconnect> tag in the same JSP file and uses the information the tag provides to determine the database URL and driver. You can also obtain the user ID and password from the <tsc:dbconnect> tag if those values are provided in the <tsc:dbconnect> tag.
- Establishes a new connection
- Retrieves and caches data in the results object.
- Closes the connection and releases the connection resource.
This section describes the syntax of the <tsx:dbquery> tag.
<%-- SELECT commands and (optional) JSP syntax can be placed within the tsx:dbquery. --%> <%-- Any other syntax, including HTML comments, are not valid. --%> <tsx:dbquery id="query_id" connection="connection_id" limit="value" > </tsx:dbquery>where...
- id
Represents the identifier of this query. The scope is the JSP file. Use id to reference the query. For example, from the <tsx:getProperty> tag, use id to display the query results.
The id is a tsx reference to the bean and can be used to retrieve the bean from the page contect. For example, if id is named mySingleDBBean, instead of using...
- if (mySingleDBBean.getValue("UISEAM",0).startsWith("N"))
use:
- com.ibm.ws.webcontainer.jsp.tsx.db.QueryResults bean = (com.ibm.ws.webcontainer.jsp.tsx.db.QueryResults)pageContext. findAttribute("mySingleDBBean"); if (bean.getValue("UISEAM",0).startsWith("N")). . .
The bean properties are dynamic and the property names are the names of the columns in the results set. If you want different column names, use the SQL keyword for specifying an alias on the SELECT command. In the following example, the database table contains columns named FNAME and LNAME, but the SELECT statement uses the AS keyword to map those column names to FirstName and LastName in the results set
Select FNAME, LNAME AS FirstName, LastName from Employee where FNAME='Jim'- connection
Represents the identifier of a <tsc:dbconnect> tag in this JSP file. The <tsc:dbconnect> tag provides the database URL, driver name, and optionally, the user ID and password for the connection.
- limit
Represents an optional attribute that constrains the maximum number of records returned by a query. If this attribute is not specified, no limit is used. In such a case, the effective limit is determined by the number of records and the system caching capability.
- SELECT command and JSP syntax
Represents the only valid SQL command, SELECT. The <tsx:dbquery> tag must return a results set. Refer to your database documentation for information about the SELECT command. See other articles in this section for a description of JSP syntax for variable data and inline Java code.
See Also
JSP files
Webapplications: Resources for learning