- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,我是 spring 的新手。我尝试使用 CallableStatementCreator 访问存储的过程,但我遇到了错误。
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SampleDataSource' defined in class path resource [StoredProcCallApplication-config.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
package Utility;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import oracle.jdbc.driver.OracleTypes;
import org.springframework.jdbc.core.CallableStatementCreator;
public class StoredProcCall implements CallableStatementCreator {
@Override
public CallableStatement createCallableStatement(Connection arg0)
throws SQLException {
// TODO Auto-generated method stub
CallableStatement cs=arg0.prepareCall("call test_proc(?,?)");
cs.setString(1,"Vivek");
cs.registerOutParameter(2, OracleTypes.CURSOR);
return cs;}}
package com;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import Utility.StoredProcCall;
import oracle.jdbc.driver.OracleTypes;
import Utility.StoredProcCall;
public class TestCallImpl {
StoredProcCall storedproccall=null;
JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource)
{this.jdbcTemplate=new JdbcTemplate(dataSource);
}
public StoredProcCall getstoredproc()
{
return storedproccall;
}
public void setstoredproc(StoredProcCall storedproccall)
{
this.storedproccall=storedproccall;
}
public void callProc()
{
List l=new ArrayList();
l.add(new SqlParameter("ename",OracleTypes.VARCHAR));
l.add(new SqlOutParameter("cur",OracleTypes.CURSOR,new RowMapper()
{
@Override
public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
// TODO Auto-generated method stub
Map m=new HashMap();
m.put("empno",arg0.getInt("empno"));
m.put("ename",arg0.getString("ename"));
return m; }}));
Map results=this.jdbcTemplate.call(new StoredProcCall(),l);
results.put("ename","Vivek");
System.out.println(results.get("ename"));}}
<?xml version="1.0" encoding="UTF-8"?> <beans --->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
<property name="dataSource" ref="SampleDataSource">
</property> </bean>
<bean id="SampleDataSource" class="org.apache.commons.dbcp.BasicDataSource" scope="singleton">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@servername"/>
<property name="username" value="admin" />
<property name="password" value="admin" />
</bean>
<bean id="storedproccall" class="Utility.StoredProcCall">
</bean>
<bean id="TestClass" class="com.TestCallImpl">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean> </beans>
最佳答案
java.lang.NoClassDefFoundError
:org/apache/commons/pool/impl/GenericObjectPool
关于java - Spring CallableStatementCreator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5856801/
嗨,我是 spring 的新手。我尝试使用 CallableStatementCreator 访问存储的过程,但我遇到了错误。 Caused by: org.springframework.beans
我正在尝试模拟(Spring boot、JUnit、Oracle) jdbcTemplate.execute(CallableStatementCreator, CallableStatementCa
我是一名优秀的程序员,十分优秀!