-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to get Out Parameters by calling stored procedure???
PostPosted: Wed Feb 08, 2012 6:04 am 
Newbie

Joined: Fri Jan 13, 2012 11:16 pm
Posts: 6
H4 ,How to get Out Parameters by calling stored procedure???
I cannot find infos from Hibernate Doc . Why???

What can I do ?
Session session = sessions.getCurrentSession();
Query query = session.getNamedQuery(storedProcedureName);

Above is right?????
Help me !
I am eager...


Last edited by fjjiaboming on Wed Feb 08, 2012 9:06 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: H4 ,How to get Out Parameters by calling stored procedure???
PostPosted: Wed Feb 08, 2012 6:52 am 
Newbie

Joined: Fri Jan 13, 2012 11:16 pm
Posts: 6
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`%` PROCEDURE `QuerySoftware`(
IN PageSize SMALLINT,
IN PageNo int,
IN OrderBy varchar(1000),
OUT Total int
)
READS SQL DATA
COMMENT '分页存储过程,查询软件表.暂不做通用.'
BEGIN
DECLARE _where varchar(1000);
-- 结束声明局部变量
-- --------------------------------
IF PageSize <= 1 OR PageSize >= 100 THEN SET PageSize = 15;
END IF;

IF PageNo < 1 THEN SET PageNo = 1;
END IF;

-- TODO
-- -------
SELECT COUNT(id) INTO Total
FROM Software x;

SELECT
Id,Name,ShortName,SoftwareVersion,Downloaded,UpdateId,Uuid,
PackageFilename,Md5,Size,HtmlDescription,Description,ShortDescription,
UpdateInfo,HtmlUpdateInfo,OsName,OsArchitecture,HomepageURL,
DownloadPageURL,DonwloadURL,Signs,Pattern,MatchType,UpdateDate,
UninstallName,ManualOrderPageNum,ManualOrderInPage,MainProgram,
UninstallProgram,SearchNames,HasPlugins,IsGreen,IsFree,IsBeta,
IsRecommended,IsHidden,IsPopping,CreateTime,CreateUser,LastEditUser,
LastEditTime,StatusId
FROM Software x;
END


---------
MySQL


Top
 Profile  
 
 Post subject: Re: How to get Out Parameters by calling stored procedure???
PostPosted: Thu Feb 09, 2012 9:08 pm 
Newbie

Joined: Fri Jan 13, 2012 11:16 pm
Posts: 6
Nobody???


Top
 Profile  
 
 Post subject: Re: How to get Out Parameters by calling stored procedure???
PostPosted: Thu Feb 09, 2012 10:54 pm 
Newbie

Joined: Thu Feb 02, 2012 11:28 pm
Posts: 13
Location: shenzhen china
Hardly see chinese in the forum!

中国同胞?

Code:
/**
     * 功能: 调用Oracle存储过程 实现流程: 1. 处理传入参数setParamList 2. 处理返回参数outParamList 3. 调用存储过程
     *
     * @param procedureDefinition 存储过程定义
     * @param setParamList 传入参数
     * @param outParamList 输出参数
     * @return void
     * @throws DataAccessException 抛出数据访问异常
     */
    public void callProcedure(String procedureDefinition, List setParamList, List outParamList)
        throws DataAccessException
    {
        Connection conn = this.getSession().connection();
        CallableStatement callableStatement = null;
        try
        {
            callableStatement = conn.prepareCall(procedureDefinition);
            if (setParamList != null)
            {
                for (int i = 0; i < setParamList.size(); i++)
                {
                    if (setParamList.get(i) instanceof Long || setParamList.get(i) instanceof Integer)
                    {
                        callableStatement.setLong(i + 1, ((Long)setParamList.get(i)).longValue());
                    }
                    else if (setParamList.get(i) instanceof String)
                    {
                        callableStatement.setString(i + 1, (String)setParamList.get(i));
                    }
                    else if (setParamList.get(i) instanceof java.util.Date)
                    {
                        callableStatement.setTimestamp(i + 1, new java.sql.Timestamp(
                            ((java.util.Date)setParamList.get(i)).getTime()));
                    }
                }
            }
            if (outParamList != null)
            {
                for (int i = 0; i < outParamList.size(); i++)
                {
                    if (outParamList.get(i) instanceof Long || outParamList.get(i) instanceof Integer)
                    {
                        callableStatement.registerOutParameter(setParamList.size() + i + 1, Types.INTEGER);
                    }
                    else if (outParamList.get(i) instanceof String)
                    {
                        callableStatement.registerOutParameter(setParamList.size() + i + 1, Types.VARCHAR);
                    }
                }
            }
            callableStatement.executeUpdate();
            if (outParamList != null)
            {
                Long l = null;
                for (int i = 0; i < outParamList.size(); i++)
                {
                    l = new Long(callableStatement.getLong(setParamList.size() + i + 1));
                    if (outParamList.get(i) instanceof Long)
                    {
                        outParamList.set(i, l);
                    }
                    else if (outParamList.get(i) instanceof Integer)
                    {
                        outParamList.set(i, l);
                    }
                    else if (outParamList.get(i) instanceof String)
                    {
                        outParamList.set(i, l);
                    }
                }
            }
        }
        catch (SQLException e)
        {
            e.printStackTrace();
            SQLExceptionTranslator translator = getHibernateTemplate().getJdbcExceptionTranslator();
            throw translator.translate("", null, e);
        }
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.