Template code Chunk output
{#example_1}
<table>

 <tr>
  <th>ID</th>
  <th>Name</td>
  <th>Flatulence Score</th>
 </tr>

{% loop in $biggest_tooters as $tooter %}
 <tr>
  <td>{$tooter.id}</td>
  <td>{$tooter.name}</td>
  <td align="center">{$tooter.flatulence}</td>
 </tr>
{% endloop %}

</table>
{#}
import com.x5.template.Theme;
import com.x5.template.Chunk;
import com.x5.db.Query;
import com.x5.util.TableData;

//...

Theme theme = new Theme("examples");
Chunk html = theme.makeChunk("loopquery#example_1");

String SQL = "SELECT id,name,flatulence FROM tooters "
	+ "WHERE flatulence > 5 "
	+ "ORDER BY flatulence DESC LIMIT 5";

Query result = db.doSelect(SQL);

//
// Since Query implements the com.x5.util.TableData interface,
// the results may be placed directly into the Chunk.
//
// The explicit cast is not necessary, just here for clarity.
//
html.set("biggest_tooters", (TableData)result);

html.render( out );
<table>

 <tr>
  <th>ID</th>
  <th>Name</td>
  <th>Flatulence Score</th>
 </tr>

 <tr>
  <td>1302</td>
  <td>Tooter McGavin</td>
  <td align="center">9.2</td>
 </tr>
 <tr>
  <td>1307</td>
  <td>Toots McGee</td>
  <td align="center">8.7</td>
 </tr>
 <tr>
  <td>1317</td>
  <td>Gassy Bob</td>
  <td align="center">8.4</td>
 </tr>
 <tr>
  <td>1304</td>
  <td>Stinky Sam</td>
  <td align="center">7.8</td>
 </tr>
 <tr>
  <td>1325</td>
  <td>Smelly Nelly</td>
  <td align="center">6.7</td>
 </tr>

</table>

ID Name Flatulence Score
1302 Tooter McGavin 9.2
1307 Toots McGee 8.7
1317 Gassy Bob 8.4
1304 Stinky Sam 7.8
1325 Smelly Nelly 6.7