如何使用IN OUT INOUT参数模式在hibernate 4中调用存储过程,

时间:2014-11-24 09:07:01

标签: hibernate-4.x

如何使用IN,OUT模式的参数调用hibernate 4中的存储过程

我想在这些详细描述的例子,谢谢你。

1 个答案:

答案 0 :(得分:0)

@覆盖     @Transactional     public SeasonTicketRefundableBean getRefendableCharges(SeasonTicketSearchBean searchBean){

    System.out.println("******************* execution start on  getRefendableCharges********************");

    SeasonTicketRefundableBean refundableBean = new SeasonTicketRefundableBean();
    **SessionImpl session1 = (SessionImpl) sessionFactory.openSession();**
    try {

            java.sql.Date sqlDate = new java.sql.Date(new Date().getTime());

            String transactionOption = searchBean.getTransactionOption();
            String ppCode = searchBean.getPpCode();
            String seasonClass = searchBean.getSeasonClass();
            String ticketType = searchBean.getTicketType();
            String renewalFromDt =  searchBean.getRenewalFromDate();
            String renewalToDt = searchBean.getRenewalToDate();
            double numRec = searchBean.getReceivedAmt();
            String vehicleCategory = searchBean.getVehicleCategory();
            double rebateAmt = searchBean.getRebateAmt();
            String receivedDt = searchBean.getIssueDate();


             //utilDate = new java.util.Date(formattedDate.toString());                                                  

            **Connection connection = session1.connection();** 
            CallableStatement callable = null;
            CallableStatement callableStatement =
               **connection.prepareCall("{call pkg_sst_transfer_season_ticket.cal_refundable_charges(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");**
            callableStatement.setString(1, transactionOption);
            callableStatement.setString(2,ppCode);
            callableStatement.setString(3, seasonClass);                             
               sqlDate = getStringToSQLDate(renewalFromDt);              
            callableStatement.setDate(4,sqlDate);                               
               sqlDate = getStringToSQLDate(renewalToDt);                
            callableStatement.setDate(5, sqlDate);
            callableStatement.setDouble(6,numRec);
            callableStatement.setString(7, vehicleCategory);
            callableStatement.setDouble(8, rebateAmt);                          
              sqlDate = getStringToSQLDate(receivedDt);
            callableStatement.setDate(9,  sqlDate);             
            callableStatement.registerOutParameter(10, Types.DOUBLE);
            callableStatement.registerOutParameter(11, Types.DOUBLE);
            callableStatement.registerOutParameter(12, Types.DOUBLE);
            callableStatement.registerOutParameter(13, Types.DOUBLE);
            callableStatement.registerOutParameter(14, Types.DOUBLE);
            callableStatement.registerOutParameter(15, Types.VARCHAR);
            callableStatement.registerOutParameter(16, Types.VARCHAR);
            callableStatement.execute();

            Double str = callableStatement.getDouble(10);

            String Errorstr = callableStatement.getString(16);

            if(Errorstr == null || Errorstr.isEmpty()){

            }
            else{
                System.out.println("Error Message is" +Errorstr);

            }

            if (str != null) {
                System.out.println(str);
                System.out.println(callableStatement.getDouble(11));
                System.out.println(callableStatement.getDouble(12));
                System.out.println(callableStatement.getDouble(13));
                System.out.println(callableStatement.getDouble(14));
                System.out.println(callableStatement.getString(15));
                System.out.println(callableStatement.getString(16));

                refundableBean.setSeasonFeePayable(callableStatement.getDouble(10));
                refundableBean.setSeasonFeePayable(callableStatement.getDouble(11));
                refundableBean.setSeasonFeeGst(callableStatement.getDouble(12));
                refundableBean.setTotalAmt(callableStatement.getDouble(13));
                refundableBean.setRebateAmt(callableStatement.getDouble(14));
            }
            else {
                ResultSet rs = callableStatement.getResultSet();
                while (rs.next()) {
                    System.out.println("Name : " + rs.getDouble(1));
                    System.out.println("Name : " + rs.getDouble(2));
                    System.out.println("Name : " + rs.getDouble(3));
                    System.out.println("Name : " + rs.getDouble(4));
                    System.out.println("Name : " + rs.getDouble(5));

                }
            }
        } catch (Exception e) {

            e.printStackTrace();
        }finally{
            session1.close();
        }

    System.out.println("******************* execution end on  getRefendableCharges********************");
        return refundableBean;
}