Spring框架下的存储过程调用
任何人都可以提供Spring框架中存储过程调用的完整示例 谢谢,Spring框架下的存储过程调用,spring,Spring,任何人都可以提供Spring框架中存储过程调用的完整示例 谢谢, Raj使用Spring存储过程框架: jdbc-config.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="h
Raj使用Spring存储过程框架: jdbc-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/orcl/DB"/>
</bean>
<bean id="storedProc" class="com.DatabaseStoredProc">
<property name="dataSource" ref="dataSource" />
<property name="sql" value="aStoredProc" />
<property name="parameters">
<list>
<bean class="org.springframework.jdbc.core.SqlParameter">
<constructor-arg index="0" value="p_id1" />
<constructor-arg index="1">
<util:constant static-field="java.sql.Types.VARCHAR" />
</constructor-arg>
</bean>
<bean class="org.springframework.jdbc.core.SqlParameter">
<constructor-arg index="0" value="p_id2" />
<constructor-arg index="1">
<util:constant static-field="java.sql.Types.VARCHAR" />
</constructor-arg>
</bean>
</list>
</property>
</bean>
</beans>
数据库存储过程类
import java.util.Map;
import org.springframework.jdbc.object.StoredProcedure;
public class DatabaseStoredProc extends StoredProcedure {
public Map<String, Object> execute(Map inputs){
Map out=super.execute(inputs);
return null;
}
// Method to map data to inputs Map:
public boolean businessRules(Object obj, Map inputs){
SomeObject otd = (SomeObject) obj;
inputs.put("p_id1", otd.getId1());
inputs.put("p_id2", otd.getId2() );
return true;
}
}
import java.util.Map;
导入org.springframework.jdbc.object.storedProcess;
公共类数据库StoredProc扩展了StoredProcess{
公共映射执行(映射输入){
映射输出=超级执行(输入);
返回null;
}
//将数据映射到输入映射的方法:
公共布尔业务规则(对象对象对象、映射输入){
SomeObject otd=(SomeObject)obj;
put(“p_id1”,otd.getId1());
put(“p_id2”,otd.getId2());
返回true;
}
}
创建一个控制器,将数据源(applicationContext.xml)注入到该控制器中:
这或多或少应该是这样的:)上述解决方案不起作用,因为您不能在子类方法中调用超类构造函数。必须使用JDBC在子类构造函数中调用它?冬眠?JPA?JDO?请添加更多详细信息!
<bean id="storedProcedureDao" class="com..myapp.SpringStoredProcedureDao">
<property name="dataSource">
<ref bean="jtdsDataSource"/>
</property>
</bean>
<bean id="jtdsDataSource" class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
<property name="serverName">
<value>servername</value>
</property>
<property name="databaseName">
<value>database</value>
</property>
<property name="user">
<value>username</value>
</property>
<property name="password">
<value>password</value>
</property>
</bean>
public class SpringStoredProcedureDao extends StoredProcedure {
private DataSource dataSource;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public CallStoredProcedure(String procedureName){
super(this.dataSource, procedureName);
compile();
}
}