Example usage for org.springframework.jdbc.core SqlOutParameter getSqlType

List of usage examples for org.springframework.jdbc.core SqlOutParameter getSqlType

Introduction

In this page you can find the example usage for org.springframework.jdbc.core SqlOutParameter getSqlType.

Prototype

public int getSqlType() 

Source Link

Document

Return the SQL type of the parameter.

Usage

From source file:cc.tooyoung.common.db.JdbcTemplate.java

/**
 * Extract output parameters from the completed stored procedure.
 * @param cs JDBC wrapper for the stored procedure
 * @param parameters parameter list for the stored procedure
 * @return Map that contains returned results
 *//*from  w  w w  .  j  a va  2s. c  o  m*/
@SuppressWarnings("unchecked")
protected Map extractOutputParameters(CallableStatement cs, List parameters) throws SQLException {
    Map returnedResults = new HashMap();
    int sqlColIndex = 1;
    for (int i = 0; i < parameters.size(); i++) {
        SqlParameter param = (SqlParameter) parameters.get(i);
        if (param instanceof SqlOutParameter) {
            SqlOutParameter outParam = (SqlOutParameter) param;
            if (outParam.isReturnTypeSupported()) {
                Object out = outParam.getSqlReturnType().getTypeValue(cs, sqlColIndex, outParam.getSqlType(),
                        outParam.getTypeName());
                returnedResults.put(outParam.getName(), out);
            } else {
                Object out = cs.getObject(sqlColIndex);
                if (out instanceof ResultSet) {
                    if (outParam.isResultSetSupported()) {
                        returnedResults.putAll(processResultSet((ResultSet) out, outParam));
                    } else {
                        String rsName = outParam.getName();
                        SqlReturnResultSet rsParam = new SqlReturnResultSet(rsName, new ColumnMapRowMapper());
                        returnedResults.putAll(processResultSet(cs.getResultSet(), rsParam));
                        ApiLogger.info("Added default SqlReturnResultSet parameter named " + rsName);
                    }
                } else {
                    returnedResults.put(outParam.getName(), out);
                }
            }
        }
        if (!(param.isResultsParameter())) {
            sqlColIndex++;
        }
    }
    return returnedResults;
}

From source file:org.springframework.jdbc.core.JdbcTemplate.java

/**
 * Extract output parameters from the completed stored procedure.
 * @param cs JDBC wrapper for the stored procedure
 * @param parameters parameter list for the stored procedure
 * @return parameters to the stored procedure
 * @return Map that contains returned results
 *///from w ww  .  ja  v a 2s. c o  m
protected Map extractOutputParameters(CallableStatement cs, List parameters) throws SQLException {
    Map returnedResults = new HashMap();
    int sqlColIndex = 1;
    for (int i = 0; i < parameters.size(); i++) {
        Object param = parameters.get(i);
        if (param instanceof SqlOutParameter) {
            SqlOutParameter outParam = (SqlOutParameter) param;
            if (outParam.isReturnTypeSupported()) {
                Object out = outParam.getSqlReturnType().getTypeValue(cs, sqlColIndex, outParam.getSqlType(),
                        outParam.getTypeName());
                returnedResults.put(outParam.getName(), out);
            } else {
                Object out = cs.getObject(sqlColIndex);
                if (out instanceof ResultSet) {
                    if (outParam.isResultSetSupported()) {
                        returnedResults.putAll(processResultSet((ResultSet) out, outParam));
                    } else {
                        logger.warn("ResultSet returned from stored procedure but a corresponding "
                                + "SqlOutParameter with a RowCallbackHandler was not declared");
                        returnedResults.put(outParam.getName(), "ResultSet was returned but not processed.");
                    }
                } else {
                    returnedResults.put(outParam.getName(), out);
                }
            }
        }
        if (!(param instanceof SqlReturnResultSet)) {
            sqlColIndex++;
        }
    }
    return returnedResults;
}