SimpleJdbcCall
不能调用多个程序
这是我的测试代码:
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());
}
}
在代码中,我定义了simpleJdbcCall
<bean id="simpleJdbcCall" class="org.springframework.jdbc.core.simple.SimpleJdbcCall" >
<constructor-arg ref="dataSource" />
</bean>
过程 proc1
接收 2 个参数,过程 proc2
接收 1 个参数。
运行时出现异常
然后调试发现AbstractJdbcCall.callString
还是
CallString:{call proc1(?, ?)}
当调用 proc2
时。
那么,这是 Spring 的错误吗?
有没有人告诉我如何联系作者 Thomas Risberg?
最佳答案
So, is it a Spring's bug ?
不,您只是使用不当。 documentation for SimpleJdbcCall
可能更明确,但它确实说:
A
SimpleJdbcCall
is a multi-threaded, reusable object representing a call to a stored procedure or a stored function.
换句话说,SimpleJdbcCall
的每个实例都被配置为调用特定的存储过程。一旦配置,不应更改。
如果需要调用多个存储过程,则需要有多个SimpleJdbcCall
对象。
关于java - SimpleJdbcCall 不能调用多个程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6592814/