Java Reference
In-Depth Information
Listing 2.1
A sample SQL mapping descriptor
<select id="getAddress"
ADR_ID as id,
ADR_DESCRIPTION as description,
ADR_STREET as street,
ADR_CITY as city,
ADR_PROVINCE as province,
ADR_POSTAL_CODE as postalCode
Here we can see a SQL SELECT statement that returns address data. From the
<select> element we can see that it takes an Integer object as a parameter, which
is marked by the #id# token in the WHERE clause. We can also see that the result is
an object instance of the Address class, which is assumed to contain the properties
of the same name as the aliases assigned to each column in the SELECT clause. For
example, the alias id would be mapped to a property of the Address class also
called id . Believe it or not, that is all it takes to map a SQL statement that receives
an integer as a parameter and returns an Address object as output. The Java code
used to execute this statement would be
Address address = (Address) sqlMap.queryForObject("getAddress",
new Integer(5));
The SQL mapping approach is a very portable concept that can be applied to any
full-featured programming language. For example, the C# code from i BATIS . NET
is nearly identical:
Address address = (Address) sqlMap.QueryForObject("getAddress", 5);
Of course there are more advanced options for mapping, especially around
results. But we'll discuss those in greater detail in part 2, “i BATIS basics.” Right
now, it's more important to understand the features and benefits of i BATIS and
how it works.
Search WWH ::

Custom Search