SimpleJdbcCall cannot call multiple procedures

SimpleJdbcCall cannot call more than one procedure

this is my test code:

 import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jdbc.core.simple.SimpleJdbcCall; public class TestCall { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring/applicationContext.xml", "spring/applicationDb.xml" }); SimpleJdbcCall call = context.getBean("simpleJdbcCall", SimpleJdbcCall.class); call.withProcedureName("proc1").execute("p1", "p2"); System.out.println("CallString: " + call.getCallString()); call.withProcedureName("proc2").execute("p1"); System.out.println("CallString: " + call.getCallString()); } } 

in code, I defined SimpleJdbcCall

 <bean id="simpleJdbcCall" class="org.springframework.jdbc.core.simple.SimpleJdbcCall" > <constructor-arg ref="dataSource" /> </bean> 

and proc1 gets 2 parameters, and proc2 gets 1 parameter.

When I launched it, an exception occurred.

I then debug it and find that AbstractJdbcCall.callString is still CallString: {call proc1(?, ?)} When calling proc2 .

So is this a Spring bug?

And is there anyone to tell me how to contact the author Thomas Riesberg?

+7
source share
2 answers

So is this a Spring bug?

No, you just use it incorrectly. The documentation for SimpleJdbcCall may be more explicit, but it says:

A SimpleJdbcCall is a multi-threaded reusable object that represents a call to a stored procedure a or a stored function.

In other words, each instance of SimpleJdbcCall configured to call a specific stored procedure. After setting, it should not be changed.

If you need to call several stored procedures, you need to have several SimpleJdbcCall objects.

+14
source

This concept is not well understood in the spring reference documentation, since all the examples in it contain only one instance of SimpleJdbcCall, which is used against one sample procedure.

One instance of SimpleJdbcCall for a unique stored procedure is what is needed, and instances of SimpleJdbcCall need to be initialized only once. They are initialized by threads.

0
source

All Articles