现在使用SSH技术开发了一个WEB应用,但是在数据层的DAO中不想使用HQL来操作数据库,而是想通过调用存储过程来操作数据库,请问,应该怎么来调用已经编写好的那些存储过程呢.
谢谢指教了
问题补充
两种情况不一样吧!
[code="java"]public class ExecuteProceduresDaoImpl extends JdbcDaoSupport implements ExecuteProceduresDao {
public Object Call_prLS_OrderByMemberOrNotMember(final String[] parm) {
String procedureSql = "{?=call prLS_OrderByMemberOrNotMember(?,?,?,?,?,?,?,?,?,?)}";
return (Object) getJdbcTemplate().execute(procedureSql, new CallableStatementCallback() {
public Object doInCallableStatement(CallableStatement cs)
throws SQLException, DataAccessException {
int j = 2;
cs.registerOutParameter(1, Types.INTEGER);
if (parm != null) {
for (int i = 0; i < parm.length; i++) {
cs.setString(j, parm[i]);
++j;
}
}
if (cs.execute()) {
ResultSet rs = cs.getResultSet();
while (rs.next()) {
rs.getString(1);
rs.getString(2);
rs.getString(3);
}
return null;
} else {
return cs.getInt(1);
}
}
});
}
}
[/code]
会用JDBC的Procedure调用方法吗?一样的处理就可以了
方式一。使用JDBC 来调用,从session 中等到Connection.
其实如果只是调用过程为什么要用hb呢用ibatis多好。。。
=。=!
getHibernateTemplate().execute(new HibernateCallback()
{
public Object doInHibernate(Session session)
throws HibernateException, SQLException
{
// 显示刷新现有的session
session.flush();
// 执行存储过程
CallableStatement stCall = session.connection()
.prepareCall("{call "+ procName + "(?, ?, ?, ?)}");
stCall.setLong(1, XX);
stCall.setLong(2, XX);
stCall.setLong(3, XX);
stCall.setLong(4, XX);
stCall.execute();
return null;
}
});