Running a query over your database is definitely worthwhile, but most applica-
tions also need to get data into the database. In this chapter, we explore some of
the ways to populate your database using the i BATIS framework. We build on the
concepts introduced in chapter 4, so if you are new to i BATIS and have not read
that chapter yet, you may want to take a quick look. Nearly all of the parameter-
mapping information (and result-mapping information too, to a small extent)
from chapter 4 will apply to nonquery mapped statements as well.
5.1 T he building blocks for updating data
In chapter 4, you learned about all of the available statement types and the parts
of the API relevant to basic queries. Here we look at the API that you will com-
monly use for executing nonquery statements, and review the mapped statement
types for updating your database.
The SqlMap API for nonquery SQL statements
We save the topic of advanced ways to update your database for the next chapter,
so for now, let's stick to the basics of insert , update , and delete —the three meth-
ods that you will most often use to update your database. We cover each of these
methods in more detail later in this chapter, but right now, we offer a brief intro-
duction, which may be enough for you to get started using them.
The insert method
As you may have guessed, the insert method is used to execute mapped state-
ments that correspond to the SQL insert statement:
Object insert(String id, Object parameterObject)
The insert method takes two parameters: the name of the mapped statement to
execute, and the parameter object to be used to build the insert statement that
will insert your data into the database.
Of the three methods that are generally used to update your database, the
insert method is unusual in that it returns Object (see section 5.2.3).
The update method
The update method is used to execute mapped statements that correspond to SQL
int update(String id, Object parameterObject)
Search WWH ::