1
A
回答
2
使用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>
DatabaseStoredProcedure类
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;
}
}
0
参照创建一个控制器你注入你的数据源( applicationContext.xml中):
<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();
}
}
这应该或多或少吧:)
0
上述解决方案将无法工作,因为您无法在子类方法中调用超类构造函数。必须在子类构造函数中调用
相关问题
- 1. 如何在Spring框架中使用HibernateTemplate调用存储过程?
- 2. 使用Spring调用存储过程JdbcBatchItemWriter
- 3. spring-data-jpa调用存储过程
- 4. 存储过程没有调用实体框架使用asp.net MVC
- 5. 调用使用Liferay框架的Java,JSP中的存储过程
- 6. 存储过程调用不工作Entrity框架5码第一
- 7. 实体框架:调用存储过程而不映射
- 8. 如何在zend框架上调用存储过程
- 9. 错误调用存储过程从实体框架
- 10. 调用实体框架中的TransactionScope中的存储过程
- 11. 从实体框架调用存储过程 - ASP.NET MVC 2
- 12. 使用实体框架调试存储过程
- 13. 实体框架4 - 调用选择/分页存储过程
- 14. 从实体框架核心调用现有存储过程
- 15. 如何在实体框架中调用sp_executesql存储过程?
- 16. 实体框架调用存储过程和地图对象
- 17. 实体框架CTP5 - 如何调用存储过程?
- 18. 如何在实体框架中调用存储过程?
- 19. 如何使用Moles存根实体框架存储过程调用?
- 20. 调用存储过程
- 21. 调用存储过程python
- 22. 调用存储过程
- 23. 调用Oracle存储过程
- 24. 调用存储过程(MVC4)
- 25. JdbcCursorItemReader - 存储过程调用
- 26. CodeFirst调用存储过程
- 27. JavaScript调用存储过程
- 28. 调用存储过程
- 29. nHibernate存储过程调用
- 30. 调用CLR存储过程
使用JDBC?休眠? JPA? JDO?请添加更多细节! – 2011-05-10 13:05:27