DDL is not officially supported in iBatis, but still many times it is executed successfully with iBatis.
I have taken a simple DDL command for creating user, which runs correctly in Oracle.
CREATE USER MYUSER IDENTIFIED BY PASSWORD;
Then used mapped statement in iBatis. The <statement>
mapped statement can hold any SQL statement. I referred Mapped Statements for iBatis from this link.
Then I have created statement for iBatis with create user DDL and passed a parameter class as UserToCreate
.
<statement id="createUser" parameterClass="UserToCreate">
CREATE USER #userName# IDENTIFIED BY PASSWORD
</statement>
The UserToCreate.java file is a bean holding data related to user to be created.
public class UserToCreate{
private String userName;
// Any other field variable
//Getter Setter methods
}
Now for calling the Create User iBatis statement just write use code:
UserToCreate user = new UserToCreate();
user.setName("MYUSER");
// sqlMap is an object of ibatis SqlMapClient
sqlMap.update("createUser", user);
This will create a new Oracle User, as specified by the user name in variable userName
.