jdbcTemplate call plsql function

总是忘记相关的语法,记录下以备查询.

 

private String genSql = "{call PACK_XXX_MGMT.INSERT_USER_TOKEN(?, ?)}"; // procedure
private String selSql = "{? = call PACK_XXX.GET_USER_ID_BY_TOKEN(?)}"; // function

 


public String someFunction(final String token) {
  String userId = null;
        try{

            userId = jdbcTemplate.execute(selSql, new CallableStatementCallback<String>() {
                public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
                    cs.registerOutParameter(1, java.sql.Types.VARCHAR);
                    cs.setString(2, token);
                    cs.execute();
                    return cs.getString(1);
                }
            });
        }catch(DataAccessException e){
            //
        }
        
        return userId;
    }

    public String someFunction() {


final String token = "hello"; final String userName = "world" jdbcTemplate.execute(genSql, new CallableStatementCallback<Void>() { public Void doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { cs.setString(1, userName); cs.setString(2, token); cs.execute(); return null; } }); return token; }

 

posted @ 2013-05-08 18:27  FangwenYu  阅读(2711)  评论(0编辑  收藏  举报