16.10.2015 Views

Getting Startedwith pureQuery

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

218<br />

<strong>Getting</strong> Started with <strong>pureQuery</strong><br />

Iterator, <strong>pureQuery</strong> closes it automatically, freeing the<br />

associated database resources. However, if you have an<br />

application that does not retrieve all the rows, you must free the<br />

database resources by closing the Iterator explicitly. Do<br />

so by casting the Iterator object as a<br />

com.ibm.pdq.runtime.ResultIterator object and<br />

calling its close() method, like this:<br />

((com.ibm.pdq.runtime.ResultIterator)<br />

myIterator).close()<br />

o<br />

o<br />

o<br />

Only the first row, in the object used to contain the row: Specify<br />

the object used to contain each row as the return type, such as<br />

MyPureQueryBean. The method returns null if the query<br />

result does not contain any rows.<br />

An object of a specific type, constructed by a<br />

com.ibm.pdq.runtime.handlers.ResultHandler<br />

object: Specify the parameterized type (represented by RES) as<br />

the return type of the method. You will have to specify the<br />

ResultHandler that will construct the object.<br />

A java.sql.ResultSet object: Specify<br />

java.sql.ResultSet as the return type of the method.<br />

11.4.1.2 Methods with the @Update annotation<br />

• What do you want the method to return?<br />

o<br />

o<br />

o<br />

An update count: Specify int as the return type if you want the<br />

method to return an update count indicating how many rows<br />

were modified.<br />

Update counts: Specify int[] as the return type if you want the<br />

method to execute the SQL statement multiple times with<br />

different parameters each time. In this case, the parameter to<br />

the method must be a java.util.List,<br />

java.util.Iterator, or array. Each entry in the List,<br />

Iterator, or array must provide the parameters for one<br />

execution of the SQL statement. <strong>pureQuery</strong> executes the SQL<br />

statement once for each entry and returns the update count from<br />

that statement in the corresponding location in the int[].<br />

void: Specify void as the return type if the SQL statement will<br />

not produce any results that you want the method to return.

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

Saved successfully!

Ooh no, something went wrong!