Example usage for java.sql Connection prepareCall

List of usage examples for java.sql Connection prepareCall

Introduction

In this page you can find the example usage for java.sql Connection prepareCall.

Prototype

CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException;

Source Link

Document

Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency.

Usage

From source file:com.netspective.axiom.sql.StoredProcedure.java

/**
 * Executes the stored procedure without any statistical logging
 *
 * @param cc              Connection context
 * @param overrideIndexes parameter indexes to override
 * @param overrideValues  parameter override values
 *//*from www.  ja v a  2s  .  co  m*/
protected QueryResultSet executeAndIgnoreStatistics(ConnectionContext cc, int[] overrideIndexes,
        Object[] overrideValues, boolean scrollable) throws NamingException, SQLException {
    if (log.isTraceEnabled())
        trace(cc, overrideIndexes, overrideValues);

    Connection conn = null;
    CallableStatement stmt = null;
    boolean closeConnection = true;
    try {
        getMetaData(cc);
        conn = cc.getConnection();
        String sql = StringUtils.strip(getSqlText(cc));
        if (scrollable)
            stmt = conn.prepareCall(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        else
            stmt = conn.prepareCall(sql);

        if (parameters != null) {
            parameters.apply(cc, stmt, overrideIndexes, overrideValues);
            stmt.execute();
            parameters.extract(cc, stmt);
            StoredProcedureParameter rsParameter = parameters.getResultSetParameter();
            if (rsParameter != null) {
                closeConnection = false;
                return (QueryResultSet) rsParameter.getExtractedValue(cc.getDatabaseValueContext());
            } else
                return null;
        } else {
            stmt.execute();
            return null;
        }
    } catch (SQLException e) {
        log.error(createExceptionMessage(cc, overrideIndexes, overrideValues), e);
        throw e;
    }
}

From source file:com.netspective.axiom.sql.StoredProcedure.java

/**
 * Executes the stored procedure and records different statistics such as database connection times,
 * parameetr binding times, and procedure execution times.
 *
 * @param overrideIndexes parameter indexes to override
 * @param overrideValues  parameter override values
 *///from  www .j  ava2s  .  com
protected QueryResultSet executeAndRecordStatistics(ConnectionContext cc, int[] overrideIndexes,
        Object[] overrideValues, boolean scrollable) throws NamingException, SQLException {
    if (log.isTraceEnabled())
        trace(cc, overrideIndexes, overrideValues);
    QueryExecutionLogEntry logEntry = execLog.createNewEntry(cc, this.getQualifiedName());
    Connection conn = null;
    CallableStatement stmt = null;
    boolean closeConnection = true;
    try {
        logEntry.registerGetConnectionBegin();
        conn = cc.getConnection();
        logEntry.registerGetConnectionEnd(conn);
        String sql = StringUtils.strip(getSqlText(cc));
        if (scrollable)
            stmt = conn.prepareCall(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        else
            stmt = conn.prepareCall(sql);

        logEntry.registerBindParamsBegin();

        if (parameters != null) {
            parameters.apply(cc, stmt, overrideIndexes, overrideValues);
            logEntry.registerBindParamsEnd();

            logEntry.registerExecSqlBegin();
            stmt.execute();
            logEntry.registerExecSqlEndSuccess();
            parameters.extract(cc, stmt);
            StoredProcedureParameter rsParameter = parameters.getResultSetParameter();
            if (rsParameter != null) {
                closeConnection = false;
                Value val = rsParameter.getValue().getValue(cc.getDatabaseValueContext());
                return (QueryResultSet) val.getValue();
            } else
                return null;
        } else {
            logEntry.registerExecSqlBegin();
            stmt.execute();
            logEntry.registerExecSqlEndSuccess();
            return null;
        }
    } catch (SQLException e) {
        logEntry.registerExecSqlEndFailed();
        log.error(createExceptionMessage(cc, overrideIndexes, overrideValues), e);
        throw e;
    }
}

From source file:com.toxind.benchmark.thrid.ibatis.sqlmap.engine.execution.SqlExecutor.java

private CallableStatement prepareCall(SessionScope sessionScope, Connection conn, String sql, Integer rsType)
        throws SQLException {
    SqlMapExecutorDelegate delegate = ((SqlMapClientImpl) sessionScope.getSqlMapExecutor()).getDelegate();
    if (sessionScope.hasPreparedStatementFor(sql)) {
        return (CallableStatement) sessionScope.getPreparedStatement((sql));
    } else {//from  www .  j  a  v a  2s . co  m
        CallableStatement cs = conn.prepareCall(sql, rsType.intValue(), ResultSet.CONCUR_READ_ONLY);
        sessionScope.putPreparedStatement(delegate, sql, cs);
        return cs;
    }
}