Domanda

I was trying to execute the DDL command for Oracle database, using iBatis. I want to execute below query using iBatis, how should I execute. I am using struts 1.2 for coding.

CREATE USER USER1..;

I have tried using the element of iBatis, but its doesn't work. Please anyone provide me quick solution for the same.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top