开发者

SimpleJdbcCall can not call more than one procedure

开发者 https://www.devze.com 2023-03-18 19:35 出处:网络
SimpleJdbcCall can not call more than one procedure this is my test code : import org.springframework.context.ApplicationContext;

SimpleJdbcCall can not 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 the code , I defined simpleJdbcCall

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

and procedure proc1 receives开发者_Python百科 2 paramaters , adn procedure proc2 receives 1 paramater.

When I run it, exception occured.

Then I debug and found out that AbstractJdbcCall.callString is still CallString: {call proc1(?, ?)} when call proc2.

So, is it a Spring's bug ?

And Is there anyone to tell me how to contact the author Thomas Risberg ?


So, is it a Spring's bug ?

No, you're just using it incorrectly. The documentation for SimpleJdbcCall could perhaps be more explicit, but it does say:

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

In other words, each instance of SimpleJdbcCall is configured to invoke a specific stored procedure. Once configured, it shouldn't be changed.

If you need to invoke multiple stored procedures, you need to have multiple SimpleJdbcCall objects.


This concept does not seem to be very clear in the spring reference documentation as all the examples in there only have a single instance of SimpleJdbcCall which is used against one example procedure.

One SimpleJdbcCall instance per unique stored procedure is what is needed and the SimpleJdbcCall instances need to be initialized only once. They are thread safe once initialized.

0

精彩评论

暂无评论...
验证码 换一张
取 消