O'Reilly logo

Java Persistence with MyBatis 3 by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mapped statements

MyBatis provides various elements to configure different types of statements, such as SELECT, INSERT, UPDATE, and DELETE. Let us see how to configure mapped statements in detail.

The INSERT statement

An INSERT query can be configured in a Mapper XML file using the <insert> element as follows:

<insert id="insertStudent" parameterType="Student">
  INSERT INTO STUDENTS(STUD_ID,NAME,EMAIL, PHONE)
  VALUES(#{studId},#{name},#{email},#{phone})
</insert>

Here, we are giving an ID insertStudent that can be uniquely identified along with the namespace com.mybatis3.mappers.StudentMapper.insertStudent. The parameterType attribute value should be a fully qualified class name or type alias name.

We can invoke this statement as follows:

int count = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required