执行SQL语句查询返回List:
public List querySQL(final String sql) {
List returnList = getHibernateTemplate().executeFind(new HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createSQLQuery(sql);
return query.list();
}
});
return returnList;
}
执行SQL语句返回行数, 也可以不返回:
public void executSQL(final String sql) {
getHibernateTemplate().execute(new HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql);
query.executeUpdate();
return null;
}
});
}