public boolean runProcedure(String procedure_name) throws SQLException
  {
    
    Connection conn = null;
    if (ds != null)
    {
      is_use_ds = true;
      conn = ds.getConnection();      
    }
    else
    {
      is_use_ds = false;
      if (conn_vec.size() > ds_vec_index)
        conn = (Connection)conn_vec.get(ds_vec_index);      
    }
    if (conn == null)
    {
      if (is_use_ds == true)
      {
       System.out.println(GlobalFun.getConvStr_SystemOut("无法通过JNDI和数据建立连接。"));
       throw new SQLException("无法通过JNDI和数据建立连接。");
      }
      else
      {
       System.out.println(GlobalFun.getConvStr_SystemOut("无法通过JDBC和数据建立连接。"));
       throw new SQLException("无法通过JDBC和数据建立连接。");
      }
    }
    String procedure = "{call " + procedure_name + " }";
    try
    {
     CallableStatement cstmt = conn.prepareCall(procedure);
     cstmt.executeUpdate();
     cstmt.close();
    }catch (SQLException ex) { return false;}
    return true;
  }这是个调用存储过程的方法,我如果用它来调用函数可以不?一个返回'0'的oracle函数,这样要修改不?

解决方案 »

  1.   

    "{ ? = call function_name(?) }";
      

  2.   

    "{ ? = call function_name(?) }";
    按照类型强制转换
      

  3.   

    "{ java.sql.Types.VARCHAR = call function_name() }"; 
    是要这样写么
      

  4.   

    String procedure = "{ ? = call " + procedure_name + " }";
    int retVal;
        try
        {
         CallableStatement cstmt = conn.prepareCall(procedure);
         cstmt.registerOutParameter(1,OracleTypes.INTEGER);
         cstmt.executeUpdate();
         retVal = cs.getInt(1);
         cstmt.close();
        }catch (SQLException ex) { return false;}    return true;
      

  5.   

    String procedure = "{ ? = call " + procedure_name + " }";
    int retVal;
        try
        {
        CallableStatement cstmt = conn.prepareCall(procedure);
        cstmt.registerOutParameter(1,OracleTypes.INTEGER);
        cstmt.executeUpdate();
        retVal = cstmt.getInt(1);
       /// cstmt.close(); 这句close最好还是写在finally里面噢
        }catch (SQLException ex) { return false;}
        finally {
    try {
    if (cstmt!= null)
    cstmt.close();
    } catch (SQLException sqle) {
    log.error(sqle);
    }
    }    return true; 
      

  6.   


    ?号是占位符号,
    从1开始,具体写法你自己查资料,这些是基础问题
    返回值ResultSet.get**(1);
    参数值:PreparedStatement.set**(1,params);
    **是返回值或者参数的数据类型
    自己研究了!