当前位置: > 数据库 > MySQL >

Spring mvc调用mysql储存过程

时间:2016-06-12 21:49来源:linux.it.net.cn 作者:IT
mysql> use modbus;
Database changed
mysql> DELIMITER $
mysql> drop procedure if exists p4;
    -> create procedure p4()
    -> begin
    -> select user_name from user_info where indexflag = 0000000001;
    -> end;
Service断
@Transactional
public List<Object> getBsmuDataByMonth(String startDate, String endDate)
{
String sql = "{call p4()}";
List<Object> list = entityDao.createSQLQuery(sql);
System.out.println("查询结果:"+list.size());
return list;
      }
// 执行SQL查询-注意 queryString是SQL语句
@SuppressWarnings("unchecked")
public List<Object> createSQLQuery(final String queryString) {
return (List<Object>) getHibernateTemplate().execute(
new HibernateCallback<Object>() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
SQLQuery query = (SQLQuery) session.createSQLQuery(
queryString).setResultTransformer(
Transformers.ALIAS_TO_ENTITY_MAP);
List<Object> rows = query.list();
return rows;
}
});
} (责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容