Java Reference
In-Depth Information
#accountId:NUMBER#,
#username:VARCHAR#, #password:VARCHAR#,
#memberSince:TIMESTAMP#,
#firstName:VARCHAR#, #lastName:VARCHAR#,
#address1:VARCHAR#, #address2:VARCHAR#,
#city:VARCHAR#, #state:VARCHAR#, #postalCode:VARCHAR#,
#country:VARCHAR#, #version:NUMBER#
)
</insert>
That was the mapped statement, and here is the code used to execute it (from a
unit test):
Account account = new Account();
account.setAccountId(new Integer(9999));
account.setUsername("inlineins");
account.setPassword("poohbear");
account.setFirstName("Inline");
account.setLastName("Example");
sqlMapClient.insert("Account.insertWithInlineInfo", account);
While this mapped statement will work, it can become verbose and difficult to
maintain once you reach the point where you have a few different versions of the
insert statement as well as some update statements, and you throw in a couple
dozen queries. When that happens, an external parameter map may help simplify
the maintenance of your SQL Map files.
5.2.2
Using an external parameter map
Along with providing the same functionality as inline parameter mapping, using
an external parameter map has the added benefit of improved performance and
additional validation at load time (which means that fewer errors slip through the
cracks during testing for your users to find at runtime).
Here is an example of an insert statement that uses an external parameter
map. The following code is functionally identical to the previous example, but
uses an external parameter map instead of an inline one:
<parameterMap id="fullParameterMapExample" class="Account">
<parameter property="accountId" jdbcType="NUMBER" />
<parameter property="username" jdbcType="VARCHAR" />
<parameter property="password" jdbcType="VARCHAR" />
<parameter property="memberSince" jdbcType="TIMESTAMP" />
<parameter property="firstName" jdbcType="VARCHAR" />
<parameter property="lastName" jdbcType="VARCHAR" />
<parameter property="address1" jdbcType="VARCHAR" />
<parameter property="address2" jdbcType="VARCHAR" />
<parameter property="city" jdbcType="VARCHAR" />
<parameter property="state" jdbcType="VARCHAR" />
Search WWH ::




Custom Search