Pass parameters in a stored procedure in Spring

Filip123go :

I have a stored procedure in my sql database and I want to call it from a java program (with spring) using @Procedure annotation. So far so good.

I call the procedure with @Procedure(procedureName = "my_procedure"). The problem is that I want to pass 2 parameters inside the procedure.

Is there a way to accomplish that using the @Procedure annotation?

Thank you very much.

Filip123go :

Ok, here is the solution!

@Procedure annotation can be used to map a method with a stored procedure if the name is the same and it is smart enough to map the method variables to the procedure parameters if they are the same type. However to commit the changes to the db , you have to use the Transactional annotation. ex.

@Procedure
@Transactional
void MyProcedureName(Integer par1 , Integer par2);

The above code will call the procedure MyProcedureName from the db and will map par1 and par2 to the MyProcedureName parameter 1 and parameter 2.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=143106&siteId=1