日期:2014-05-18 浏览次数:20622 次
CallableStatement proc =connection.prepareCall("{call youproc(?)}"); proc.setString(1, "hello"); ResultSet rs = proc.executeQuery();
------解决方案--------------------
hibernate 配置文件
<hibernate-mapping package="com.unmi.vo">
<class name="Test" table="TEST">
............
</class>
<sql-query callable="true" name="selectAllUsers">
<return alias="aa" class="Test">
<return-property name="oborqt" column="OBORQT"/>
<return-property name="moorqt" column="MOORQT"/>
<return-property name="roschn" column="ROSCHN"/>
<return-property name="plandate" column="PLANDATE"/>
</return>
{ ? = call selectAllUsers() }
</sql-query>
</hibernate-mapping>
{ ? = call selectAllUsers() } 也可以写成{ call selectAllUsers() },
如果有参数就写成
{ ? = call selectAllUsers(?,?,?) }
代码中对query设置相应位置上的值就OK
——————————————————————————————————
Java调用关键代码如下
Session session = HibernateUtil.currentSession();
Query query = session.getNamedQuery("selectAllUsers");
List list = query.list();
System.out.println(list);