如何在liferay中调用存储过程? [英] How to call stored procedure in liferay?

查看:89
本文介绍了如何在liferay中调用存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我指的是使用动态在Liferay中并使用MySQL 5.5进行查询,但我们需要调用存储过程来代替涉及多个实体的自定义查询. 我们创建了一个示例过程

I am referring Using dynamic query in Liferay and using MySQL 5.5 but instead of custom queries involving multiple entities,we need to call a stored procedure. We have created a sample procedure

delimiter //
Create Procedure proc_check (OUT count INT)
begin
select count(*) into count from lg_office ;
end//

在default.xml中,我们使用了包含自定义查询的

In default.xml,containing custom queries,we have used

<sql id="de.uhh.l2g.plugins.service.persistence.ProducerFinder.findOfficeCount">
        <![CDATA[
            Call proc_check(@output)
        ]]>
    </sql>

在相应的Finder方法中,我们使用下面的代码段调用存储的proc,并在开始和结束处均传递-1.

In the respective Finder method,we used the below snippet to call the stored proc,passing -1 for both begin and end.

String sql = CustomSQLUtil.get(FIND_OFFICE_COUNT);
            SQLQuery q = session.createSQLQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            //qPos.add(lectureseriesId);
            List <Integer> sl =  (List<Integer>) QueryUtil.list(q, getDialect(), begin, end);   
            return sl;

在QueryUtil中,我们找不到其他适用的方法来执行调用. 发布此消息后,我们将收到以下错误

In QueryUtil,we could not find other applicable methods to execute the call. Post this we get the below error

ERROR [RuntimePageImpl-5][JDBCExceptionReporter:82] ResultSet is from UPDATE. No Data.

这种方法是正确的吗?如果缺少某些东西,请提出达到相同目的的方法.

Is this approach correct with something missing or if not,please suggest approach to achieve the same.

推荐答案

liferay中没有内置的任何实用程序来调用存储过程,但是您可以通过DataAccess.getConnection();获得连接并像这样使用jdbc api方式

there isn't any utility built-in in liferay to call stored procedure but you can just get the connection with DataAccess.getConnection(); and use the jdbc api like this way

 Connection connection =DataAccess.getConnection();
 CallableStatement cs  = connection.prepareCall("{Call proc_check(@output)}");
 ResultSet rs = cs.executeQuery();

这篇关于如何在liferay中调用存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆