| <?xml version="1.0"?> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <j:jelly xmlns:j="jelly:core" xmlns:sql="jelly:sql" xmlns:log="jelly:log"> |
| |
| <sql:setDataSource |
| url="${databaseUrl}" |
| driver="${databaseDriver}" |
| user="${databaseUser}" |
| password="${databasePassword}"/> |
| |
| <j:set var="databaseTable" value="dummy"/> |
| |
| |
| <log:info>Dropping and recreating the table ${databaseTable}...</log:info> |
| |
| <j:catch> |
| <!-- ignore any exceptions --> |
| <sql:update> |
| drop table ${databaseTable} |
| </sql:update> |
| </j:catch> |
| |
| <sql:update> |
| create table ${databaseTable} ( |
| id integer, |
| name varchar(255) |
| ) |
| </sql:update> |
| |
| |
| <log:info>Inserting some data...</log:info> |
| |
| <j:forEach begin="1" end="20" var="i"> |
| <sql:update> |
| insert into ${databaseTable} (id, name) values (?, ?) |
| <sql:param value="${i}"/> |
| <sql:param value="Foo_${i}"/> |
| </sql:update> |
| |
| </j:forEach> |
| |
| <log:info>Now performing a query...</log:info> |
| |
| <sql:query var="results"> |
| select * from ${databaseTable} |
| </sql:query> |
| |
| <dataSet> |
| |
| <!-- we'll turn off whitespace trimming for the loop --> |
| <j:forEach trim="false" items="${results.rowsByIndex}" var="row"> |
| <row> |
| <j:forEach var="columnName" items="${results.columnNames}" indexVar="i"> |
| <field column="${columnName}">${row[i]}</field> |
| </j:forEach> |
| </row> |
| </j:forEach> |
| |
| </dataSet> |
| |
| </j:jelly> |
| |
| |