【问题标题】:how to call stored procedure in hibernate 4 with IN OUT INOUT modes of parameters ,如何使用 IN OUT INOUT 参数模式在休眠 4 中调用存储过程,
【发布时间】:2014-11-24 09:07:01
【问题描述】:

如何在hibernate 4中调用带有IN、OUT参数模式的存储过程,

我想要详细说明这些示例,在此先感谢。

【问题讨论】:

    标签: hibernate-4.x


    【解决方案1】:

    @覆盖 @Transactional 公共 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;
    }
    

    【讨论】:

    猜你喜欢
    • 2011-07-29
    • 2012-04-18
    • 2021-05-18
    • 1970-01-01
    • 2020-09-22
    • 2018-06-18
    • 2019-02-20
    • 2018-09-19
    相关资源
    最近更新 更多