2017-06-09 26 views
0

私は、simpleJdbcCall.executeFunctionから単一のプリミティブ結果を得るという一連の例を見てきました。私は一連の結果にアクセスする方法を知る必要があります。 executeMapを返します。 SqlOutParameterexecuteFunctionを入力し、返すタイプを教えてください。さて、私はMyCustomClass.classに戻り値をマッピングし、nullを返しています。私は関数が戻り値3 BIGINTを知っていることを知っている。executeFunctionから複数の戻り値にアクセスするには?

public class MyDao { 
    private final JdbcTemplate theTemplate;; 

    //@Autowired ctor 

    public long createCategory(final CategoryEntity category) { 
     final SimpleJdbcCall jdbcCall = getJdbcCall(); 

     return mapResult(jdbcCall.executeFunction(MyResultEntity.class, fromEntity(category))); 
    } 

    private long mapResult(MyResultEntity result) { 
     return result.getOut_id();//FAIL 
    } 

    private SqlParameterSource fromEntity(final MyEntity category) { 
     Map<String,Object> params = new HashMap<>(); 

     params.put("in_name", category.getName()); 
     params.put("in_description", category.getDescription()); 

     SqlParameterSource result = new MapSqlParameterSource(params); 

     return result; 
    } 

    private SimpleJdbcCall getJdbcCall() { 
     //I need the value returned by "out_id" 
     SimpleJdbcCall jdbcCall = new SimpleJdbcCall(theTemplate) 
       .withSchemaName("mySchema") 
       .withFunctionName("my_function") 
       .declareParameters(
         new SqlOutParameter("out_id", Types.BIGINT), 
         new SqlOutParameter("out_2", Types.BIGINT), 
         new SqlOutParameter("out_3", Types.BIGINT) 
       ); 

       return jdbcCall; 
    } 
} 

答えて

0

executeを使用して関数を呼び出すこともできます。次に、Mapを使用して結果を取得してください:

public long createCategory(final MyEntity category) { 
    final SimpleJdbcCall jdbcCall = getJdbcCall(); 

    Map<String, Object> results = jdbcCall.execute(fromEntity(category)); 
    return (long) results.get("out_id"); 
} 
関連する問題