存储过程如下create procedure pre_allRate (p_cust_no       in  varchar2,
                         p_cust_rate     out varchar2,
                         p_template_rate out varchar2)
as
  v_cust_rate     varchar2(255);
  v_template_rate varchar2(255);
  v_count         int;
begin
select cust_no||','||
       exch_code||','||
       vari_code||','||
       deliv_date||','||
       eo_commi_amt||','||
       eo_commi_rate||','||
       eo_add_fee1_amt||','||
       eo_add_fee1_rate||','||
       eo_add_fee2_amt||','||
       eo_add_fee2_rate||','||
       ot_commi_amt||','||
       ot_commi_rate||','||
       ot_add_fee1_amt||','||
       ot_add_fee1_rate||','||
       ot_add_fee2_amt||','||
       ot_add_fee2_rate||','||
       deliv_commi_amt||','||
       deliv_commi_rate||','||
       oper_code||','||
       oper_date||','||
       oper_time
  into v_cust_rate 
  from SYB_CUST_COMMI 
 where cust_no=p_cust_no;
 p_cust_rate:=v_cust_rate; 
 p_template_rate:='null';
exception
 when NO_DATA_FOUND
 then
         select count(*) 
           into v_count
           from SYB_COMMI_TEMPLATE;
         if v_count>0
         then
             select TEMPLATE_NO||','||
                    EXCH_CODE||','||
                    VARI_CODE||','||
                    DELIV_DATE||','||
                    EO_COMMI_AMT||','||
                    EO_COMMI_RATE||','||
                    EO_ADD_FEE1_AMT||','||
                    EO_ADD_FEE1_RATE||','||
                    EO_ADD_FEE2_AMT||','||
                    EO_ADD_FEE2_RATE||','||
                    OT_COMMI_AMT||','||
                    OT_COMMI_RATE||','||
                    OT_ADD_FEE1_AMT||','||
                    OT_ADD_FEE1_RATE||','||
                    OT_ADD_FEE2_AMT||','||
                    OT_ADD_FEE2_RATE||','||
                    DELIV_COMMI_AMT||','||
                    DELIV_COMMI_RATE||','||
                    OPER_CODE||','||
                    OPER_DATE||','||
                    OPER_TIME
               into v_template_rate  
               from SYB_COMMI_TEMPLATE;
               p_cust_rate:='null';
               p_template_rate:=v_template_rate;
           else
               p_cust_rate:='null';
               p_template_rate:='null';
           end if;
end pre_allRate;————————————————————————————————————我写的一个java代码(SSH的DAO中)
public int execProce(String custNo) throws Exception{
// 第一个问号是返回值,后面问号是传入参数 
String call = "{?=call pre_ALLRATE(?)}"; 
CallableStatement callableStatement=null;
Connection conn = getSession().connection(); 
try { 
callableStatement =conn.prepareCall(call);
int i = 1; 
callableStatement.registerOutParameter(1,  
java.sql.Types.VARCHAR); 
callableStatement.setString(1, custNo);
callableStatement.execute(); 
int reValue = callableStatement.getInt(1); 
return reValue ; 
} catch (SQLException e) { 
e.printStackTrace();
throw new Exception("调用存储过程出错");} }
}
方案二:Connection con = null; 
CallableStatement toesUp = null; 
try { 
con = ConnectionPool.getConnection(); 
con.setAutoCommit(false); 
CallableStatement toesUp = connection.prepareCall("{ ? = pre_ALLRATE () }"); 
toesUp.registerOutParameter(1, Types.OTHER); 
toesUp.execute(); 
ResultSet rs = (ResultSet) toesUp.getObject(1); 
while (rs.next()) { 
String str = rs.getString(1);  //这里肯定有问题~~~ 
mapper.sendDeath(str); 

rs.close(); 
} catch (SQLException e) { 
toesUp.close(); 
con.close(); 

存储过程执行后会得到一个字符串,我想在java代码中得到并返回 请高手帮我修改下

解决方案 »

  1.   

            Connection con=null;
    ResultSet rs = null;    
            String sql = "rptCust '"+sc+"'"; 
            con = DatabaseConnection.getConnection(); 
             PreparedStatement stmt  = con.prepareStatement(sql); 
            rs = stmt.executeQuery(); 
    推荐这种方式,rptCust为存储过程名,sc为参数,后边可以跟多个参数。返回记录:
    while (rs.next()){
    String ID = rs.getString("ID");
    }
      

  2.   

    我是这样做的:
    CallableStatement statement = connection.prepareCall("{call proc_masbiz_event(?, ?, ?, ?)}");
    statement.setInt(1, param.getSysuserId());
    statement.setString(2, param.getEventDate());
    statement.setString(3, param.getEndDate());
    statement.setInt(4, param.getIs_share());
    ResultSet rs = statement.executeQuery();
    while (rs.next())
    {
    ......
    }
      

  3.   

    在你的存储过程的into v_cust_rate vcr
    加个别名看看, 用rs.getString("vcr")取看看