10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

}<br />

Connection connection;<br />

if (cid != null) {<br />

// there is a connection id, use it<br />

connection =(Connection)pageContext.<br />

getAttribute(cid);<br />

} else {<br />

ConnectionTag ancestorTag =<br />

(ConnectionTag)findAncestorWithClass(this,<br />

ConnectionTag.class);<br />

if (ancestorTag == null) {<br />

throw new JspTagException("A query without<br />

a connection attribute must be nested<br />

within a connection tag.");<br />

}<br />

connection = ancestorTag.getConnection();<br />

...<br />

}<br />

<strong>The</strong> query tag implemented by this tag handler can be used in either of the following ways:<br />

<br />

...<br />

<br />

<br />

SELECT account, balance FROM acct_table<br />

where customer_number = ?<br />

<br />

<br />

<br />

<br />

SELECT account, balance FROM acct_table<br />

where customer_number = ?<br />

<br />

<br />

<br />

<strong>The</strong> TLD for the tag handler use the following declaration to indicate that the connectionId<br />

attribute is optional:<br />

<br />

...<br />

<br />

connectionId<br />

false<br />

<br />

<br />

ProgrammingTagsThat Accept Scripting Elements<br />

Chapter 9 • Scripting in JSP Pages 281

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!