Example usage for java.sql PreparedStatement setMaxFieldSize

List of usage examples for java.sql PreparedStatement setMaxFieldSize

Introduction

In this page you can find the example usage for java.sql PreparedStatement setMaxFieldSize.

Prototype

void setMaxFieldSize(int max) throws SQLException;

Source Link

Document

Sets the limit for the maximum number of bytes that can be returned for character and binary column values in a ResultSet object produced by this Statement object.

Usage

From source file:com.xqdev.sql.MLSQL.java

private static void configureStatement(PreparedStatement stmt, int maxRows, int queryTimeout, int maxFieldSize)
        throws SQLException {
    if (maxRows != -1) {
        stmt.setMaxRows(maxRows);/*from ww w  .  j ava  2s.  co  m*/
    }
    if (queryTimeout != -1) {
        stmt.setQueryTimeout(queryTimeout);
    }
    if (maxFieldSize != -1) {
        stmt.setMaxFieldSize(maxFieldSize);
    }
}

From source file:org.wso2.carbon.dataservices.core.description.query.SQLQuery.java

private PreparedStatement createProcessedPreparedStatement(int queryType, InternalParamCollection params,
        Connection conn) throws DataServiceFault {
    try {//w ww  . ja  v  a 2s. c  o  m
        /*
         * lets see first if there's already a batch prepared statement
         * created
         */
        boolean inTheMiddleOfABatch = false;
        PreparedStatement stmt = this.getBatchPreparedStatement();
        int currentParamCount = this.getParamCount();

        /* create a new prepared statement */
        if (stmt == null) {
            /* batch mode is not supported for dynamic queries */
            Object[] result = this.processDynamicQuery(this.getQuery(), params);
            String dynamicSQL = (String) result[0];
            currentParamCount = (Integer) result[1];
            String processedSQL = this.createProcessedQuery(dynamicSQL, params, currentParamCount);
            if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
                if (this.isReturnGeneratedKeys()) {
                    if (this.getKeyColumns() != null) {
                        stmt = conn.prepareStatement(processedSQL, this.getKeyColumns());
                    } else {
                        stmt = conn.prepareStatement(processedSQL, Statement.RETURN_GENERATED_KEYS);
                    }
                } else {
                    stmt = conn.prepareStatement(processedSQL);
                }
            } else if (queryType == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
                stmt = conn.prepareCall(processedSQL);
            } else {
                throw new DataServiceFault("Unsupported query type: " + queryType);
            }
        } else {
            inTheMiddleOfABatch = true;
        }

        if (!inTheMiddleOfABatch) {
            /* set query timeout */
            if (this.isHasQueryTimeout()) {
                stmt.setQueryTimeout(this.getQueryTimeout());
            }
            /* adding the try catch to avoid setting this for jdbc drivers that do not implement this method. */
            try {
                /* set fetch direction */
                if (this.isHasFetchDirection()) {
                    stmt.setFetchDirection(this.getFetchDirection());
                }
                /* set fetch size - user's setting */
                if (this.isHasFetchSize()) {
                    stmt.setFetchSize(this.getFetchSize());
                } else {
                    /*
                     * stream data by sections - avoid the full result set
                     * to be loaded to memory, and only stream if there
                     * aren't any OUT parameters, MySQL fails in the
                     * scenario of streaming and OUT parameters, so the
                     * possibility is there for other DBMSs
                     */
                    if (!this.hasOutParams() && this.getFetchSizeProperty().isChangeFetchSize()) {
                        stmt.setFetchSize(this.getFetchSizeProperty().getFetchSize());
                    }
                }
            } catch (Throwable e) {
                log.debug("Exception while setting fetch size: " + e.getMessage(), e);
            }
            /* set max field size */
            if (this.isHasMaxFieldSize()) {
                stmt.setMaxFieldSize(this.getMaxFieldSize());
            }
            /* set max rows */
            if (this.isHasMaxRows()) {
                stmt.setMaxRows(this.getMaxRows());
            }
        }

        int currentOrdinal = 0;
        InternalParam param;
        ParamValue value;
        for (int i = 1; i <= currentParamCount; i++) {
            param = params.getParam(i);
            value = param.getValue();
            /*
             * handle array values, if value is null, this param has to be
             * an OUT param
             */
            if (value != null && value.getValueType() == ParamValue.PARAM_VALUE_ARRAY) {
                for (ParamValue arrayElement : value.getArrayValue()) {
                    this.setParamInPreparedStatement(stmt, param,
                            arrayElement == null ? null : arrayElement.toString(), queryType, currentOrdinal);
                    currentOrdinal++;
                }
            } else { /* scalar value */
                this.setParamInPreparedStatement(stmt, param, value != null ? value.getScalarValue() : null,
                        queryType, currentOrdinal);
                currentOrdinal++;
            }
        }

        /* if we are in JDBC batch processing mode, batch it! */
        if (this.isJDBCBatchRequest()) {
            stmt.addBatch();
        }

        return stmt;
    } catch (SQLException e) {
        throw new DataServiceFault(e, "Error in 'createProcessedPreparedStatement'");
    }
}