Example usage for java.sql CallableStatement setQueryTimeout

List of usage examples for java.sql CallableStatement setQueryTimeout

Introduction

In this page you can find the example usage for java.sql CallableStatement setQueryTimeout.

Prototype

void setQueryTimeout(int seconds) throws SQLException;

Source Link

Document

Sets the number of seconds the driver will wait for a Statement object to execute to the given number of seconds.

Usage

From source file:com.adaptris.jdbc.StoredProcedure.java

public JdbcResult execute() throws CoreException {

    try {//  w ww .  ja v  a2 s . c om
        String sqlStatement = getStatementCreator().createCall(getName(), getParameters().size());
        log.trace("Generated SQL Statement [{}]", sqlStatement);
        CallableStatement statement = getConnection().prepareCall(sqlStatement);
        if (timeout > 0) {
            statement.setQueryTimeout((int) TimeUnit.MILLISECONDS.toSeconds(this.getTimeout()));
        }
        applyInParameters(statement);

        JdbcResult results = statementExecutor.executeCallableStatement(statement);

        translateResultSet(getAdaptrisMessage(), results);

        applyOutParameters(statement);
        results.setParameters(getParameters());

        return results;

    } catch (SQLException e) {
        throw new CoreException(e);
    }
}

From source file:nl.nn.adapterframework.jdbc.XmlQuerySender.java

private String executeUpdate(Connection connection, String correlationID, String tableName, String query,
        Vector columns) throws SenderException {
    try {/*from w w w.  j a  v  a2 s .  c  o m*/
        if (existLob(columns)) {
            CallableStatement callableStatement = getCallWithRowIdReturned(connection, correlationID, query);
            applyParameters(callableStatement, columns);
            int ri = 1 + countParameters(columns);
            callableStatement.registerOutParameter(ri, Types.VARCHAR);
            callableStatement.setQueryTimeout(getTimeout());
            int numRowsAffected = callableStatement.executeUpdate();
            String rowId = callableStatement.getString(ri);
            log.debug(getLogPrefix() + "returning ROWID [" + rowId + "]");

            Iterator iter = columns.iterator();
            while (iter.hasNext()) {
                Column column = (Column) iter.next();
                if (column.getType().equalsIgnoreCase(TYPE_BLOB)
                        || column.getType().equalsIgnoreCase(TYPE_CLOB)) {
                    query = "SELECT " + column.getName() + " FROM " + tableName + " WHERE ROWID=?"
                            + " FOR UPDATE";
                    PreparedStatement statement = getStatement(connection, correlationID, query, true);
                    statement.setString(1, rowId);
                    statement.setQueryTimeout(getTimeout());
                    if (column.getType().equalsIgnoreCase(TYPE_BLOB)) {
                        executeUpdateBlobQuery(statement, column.getValue());
                    } else {
                        executeUpdateClobQuery(statement, column.getValue());
                    }
                }
            }
            return "<result><rowsupdated>" + numRowsAffected + "</rowsupdated></result>";
        }
        PreparedStatement statement = getStatement(connection, correlationID, query, false);
        applyParameters(statement, columns);
        statement.setQueryTimeout(getTimeout());
        return executeOtherQuery(connection, correlationID, statement, query, null, null);
    } catch (Throwable t) {
        throw new SenderException(t);
    }
}

From source file:org.guzz.transaction.AbstractTranSessionImpl.java

/**
 * Apply the current query timeout, if any, to the current <code>java.sql.CallableStatement</code>.
 * //from   w  ww  .  j  a v  a 2s.  c  o m
 * @param cs java.sql.CallableStatement
 * @see java.sql.CallableStatement#setQueryTimeout
 */
public void applyQueryTimeout(java.sql.CallableStatement cs) {
    if (hasQueryTimeout()) {
        try {
            cs.setQueryTimeout(getQueryTimeoutInSeconds());
        } catch (SQLException e) {
            throw new JDBCException("failed to setQueryTimeout to :" + getQueryTimeoutInSeconds(), e,
                    e.getSQLState());
        }
    }
}

From source file:org.opoo.oqs.spring.SpringQuery.java

protected Object doCall() throws QueryException {
    final PreparedStatementSetter pss = new ArgTypePreparedStatementSetter(valueArray(), typeArray());
    final ResultSetExtractor rse = createResultSetExtractor(createListResultSetHandler());
    return jdbcTemplate.execute(getSql(), new CallableStatementCallback() {
        public Object doInCallableStatement(CallableStatement callableStatement)
                throws SQLException, DataAccessException {

            if (getQueryTimeout() > 0) {
                callableStatement.setQueryTimeout(getQueryTimeout());
            }//from  ww w.  ja  v  a  2  s  .  com

            pss.setValues(callableStatement);

            boolean retVal = callableStatement.execute();
            int updateCount = callableStatement.getUpdateCount();
            if (log.isDebugEnabled()) {
                log.debug("CallableStatement.execute() returned '" + retVal + "'");
                log.debug("CallableStatement.getUpdateCount() returned " + updateCount);
            }

            ResultSet rs = callableStatement.getResultSet();
            try {
                if (rs != null && rse != null) {
                    return rse.extractData(rs);
                }
            } finally {
                JdbcUtils.closeResultSet(rs);
            }

            if (updateCount > 0) {
                return new Integer(updateCount);
            }
            return null;
        }
    });
}