Monday, July 4, 2011

CRUD Operation in iBatis

1. To return a single value in iBatis Use "queryForObject"

Eg: select userName from user where user_id=2;

2. To return a set of Values in iBatis use "queryForList"

Eg: select * from user

3.Update Query goes here

4. Delete query goes here

5. Insert query goes here

Inser Query



SELECT SEQ_ID.NEXTVAL AS ID FROM DUAL

INSERT INTO User(
userName
)VALUES(
#userName:VARCHAR#
)


From SQL MAP DAO
testVO.setUserName(testVO.getUserName);
insert("createUser", testVO);

Simple Select Query with no Filters

1. Create a Valued Object Which contains the Column of Table (Simple Getter & Setter)

Eg:

TestVO.java

private String userName;

public final String getUserName() {
return userName;
}

public final void setUserName(String userName) {
this.userName= userName;
}

2. Refer this VO in the defined XML File which has the DB related Queries



3.



4.
Note : Here the Parameter calss test contains null .
public List getuserList() {
return queryForList("getUsersList", null);
}