⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serverpreparedstatement.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*      Copyright (C) 2002-2004 MySQL AB      This program is free software; you can redistribute it and/or modify      it under the terms of version 2 of the GNU General Public License as       published by the Free Software Foundation.      There are special exceptions to the terms and conditions of the GPL       as it is applied to this software. View the full text of the       exception in file EXCEPTIONS-CONNECTOR-J in the directory of this       software distribution.      This program is distributed in the hope that it will be useful,      but WITHOUT ANY WARRANTY; without even the implied warranty of      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      GNU General Public License for more details.      You should have received a copy of the GNU General Public License      along with this program; if not, write to the Free Software      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package com.mysql.jdbc;import com.mysql.jdbc.profiler.ProfileEventSink;import com.mysql.jdbc.profiler.ProfilerEvent;import java.io.IOException;import java.io.InputStream;import java.io.Reader;import java.io.UnsupportedEncodingException;import java.math.BigDecimal;import java.net.URL;import java.sql.Array;import java.sql.Blob;import java.sql.Clob;import java.sql.Date;import java.sql.ParameterMetaData;import java.sql.Ref;import java.sql.SQLException;import java.sql.Time;import java.sql.Types;import java.util.ArrayList;import java.util.BitSet;import java.util.Calendar;import java.util.Locale;import java.util.TimeZone;/** * JDBC Interface for MySQL-4.1 and newer server-side PreparedStatements. * * @author Mark Matthews * @version $Id: ServerPreparedStatement.java,v 1.1.2.68 2005/02/17 21:42:27 mmatthews Exp $ */public class ServerPreparedStatement extends PreparedStatement {    /* 1 (length) + 2 (year) + 1 (month) + 1 (day) */    private static final byte MAX_DATE_REP_LENGTH = (byte) 5;    /*      1 (length) + 1 (is negative) + 4 (day count) + 1 (hour)      + 1 (minute) + 1 (seconds) + 4 (microseconds)    */    private static final byte MAX_TIME_REP_LENGTH = 13;    /*      1 (length) + 2 (year) + 1 (month) + 1 (day) +      1 (hour) + 1 (minute) + 1 (second) + 4 (microseconds)    */    private static final byte MAX_DATETIME_REP_LENGTH = 12;    private Buffer outByteBuffer;    /** The Calendar instance used to create date/time bindings */    private Calendar dateTimeBindingCal = null;    /** If this statement has been marked invalid, what was the reason? */    private SQLException invalidationException;    /** Bind values for individual fields */    private BindValue[] parameterBindings;    /** Field-level metadata for parameters */    private Field[] parameterFields;    /** Field-level metadata for result sets. */    private Field[] resultFields;    /**     * Flag indicating whether or not the long parameters have been 'switched'     * back to normal parameters. We can not execute() if clearParameters()     * hasn't been called in this case.     */    private boolean detectedLongParameterSwitch = false;    /** Has this prepared statement been marked invalid? */    private boolean invalid = false;    /** Does this query modify data? */    private boolean isSelectQuery;    /** Do we need to send/resend types to the server? */    private boolean sendTypesToServer = false;    /**     * The number of fields in the result set (if any) for this     * PreparedStatement.     */    private int fieldCount;    /** The type used for string bindings, changes from version-to-version */    private int stringTypeCode = MysqlDefs.FIELD_TYPE_STRING;    /** The ID that the server uses to identify this PreparedStatement */    private long serverStatementId;    /**     * Creates a new ServerPreparedStatement object.     *     * @param conn the connection creating us.     * @param sql the SQL containing the statement to prepare.     * @param catalog the catalog in use when we were created.     *     * @throws SQLException If an error occurs     */    public ServerPreparedStatement(Connection conn, String sql, String catalog)        throws SQLException {        super(conn, catalog);        checkNullOrEmptyQuery(sql);        this.isSelectQuery = StringUtils.startsWithIgnoreCaseAndWs(sql, "SELECT"); //$NON-NLS-1$        this.useTrueBoolean = this.connection.versionMeetsMinimum(3,                21, 23);        this.hasLimitClause = (StringUtils.indexOfIgnoreCase(sql, "LIMIT") != -1); //$NON-NLS-1$        this.firstCharOfStmt = StringUtils.firstNonWsCharUc(sql);        this.originalSql = sql;        if (this.connection.versionMeetsMinimum(4, 1, 2)) {            this.stringTypeCode = MysqlDefs.FIELD_TYPE_VAR_STRING;        } else {            this.stringTypeCode = MysqlDefs.FIELD_TYPE_STRING;        }        try {            serverPrepare(sql);        } catch (SQLException sqlEx) {            // don't wrap SQLExceptions            throw sqlEx;        } catch (Exception ex) {            throw new SQLException(ex.toString(),                SQLError.SQL_STATE_GENERAL_ERROR);        }    }    /**     * @see java.sql.PreparedStatement#setArray(int, java.sql.Array)     */    public void setArray(int i, Array x) throws SQLException {        throw new NotImplemented();    }    /**     * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream,     *      int)     */    public void setAsciiStream(int parameterIndex, InputStream x, int length)        throws SQLException {        checkClosed();        if (x == null) {            setNull(parameterIndex, java.sql.Types.BINARY);        } else {            BindValue binding = getBinding(parameterIndex, true);            setType(binding, MysqlDefs.FIELD_TYPE_BLOB);            binding.value = x;            binding.isNull = false;            binding.isLongData = true;            if (this.connection.getUseStreamLengthsInPrepStmts()) {                binding.bindLength = length;            } else {                binding.bindLength = -1;            }            serverLongData(parameterIndex, binding);        }    }    /**     * @see java.sql.PreparedStatement#setBigDecimal(int, java.math.BigDecimal)     */    public void setBigDecimal(int parameterIndex, BigDecimal x)        throws SQLException {        checkClosed();        if (x == null) {            setNull(parameterIndex, java.sql.Types.DECIMAL);        } else {            setString(parameterIndex, StringUtils.fixDecimalExponent(x.toString()));        }    }    /**     * @see java.sql.PreparedStatement#setBinaryStream(int,     *      java.io.InputStream, int)     */    public void setBinaryStream(int parameterIndex, InputStream x, int length)        throws SQLException {        checkClosed();        if (x == null) {            setNull(parameterIndex, java.sql.Types.BINARY);        } else {            BindValue binding = getBinding(parameterIndex, true);            setType(binding, MysqlDefs.FIELD_TYPE_BLOB);            binding.value = x;            binding.isNull = false;            binding.isLongData = true;            if (this.connection.getUseStreamLengthsInPrepStmts()) {                binding.bindLength = length;            } else {                binding.bindLength = -1;            }            serverLongData(parameterIndex, binding);        }    }    /**     * @see java.sql.PreparedStatement#setBlob(int, java.sql.Blob)     */    public void setBlob(int parameterIndex, Blob x) throws SQLException {        checkClosed();        if (x == null) {            setNull(parameterIndex, java.sql.Types.BINARY);        } else {            BindValue binding = getBinding(parameterIndex, true);            setType(binding, MysqlDefs.FIELD_TYPE_BLOB);            binding.value = x;            binding.isNull = false;            binding.isLongData = true;            if (this.connection.getUseStreamLengthsInPrepStmts()) {                binding.bindLength = x.length();            } else {                binding.bindLength = -1;            }            serverLongData(parameterIndex, binding);        }    }    /**     * @see java.sql.PreparedStatement#setBoolean(int, boolean)     */    public void setBoolean(int parameterIndex, boolean x)        throws SQLException {        setByte(parameterIndex, (x ? (byte) 1 : (byte) 0));    }    /**     * @see java.sql.PreparedStatement#setByte(int, byte)     */    public void setByte(int parameterIndex, byte x) throws SQLException {        checkClosed();        BindValue binding = getBinding(parameterIndex, false);        setType(binding, MysqlDefs.FIELD_TYPE_TINY);        binding.value = null;        binding.byteBinding = x;        binding.isNull = false;        binding.isLongData = false;    }    /**     * @see java.sql.PreparedStatement#setBytes(int, byte)     */    public void setBytes(int parameterIndex, byte[] x)        throws SQLException {        checkClosed();        if (x == null) {            setNull(parameterIndex, java.sql.Types.BINARY);        } else {            BindValue binding = getBinding(parameterIndex, false);            setType(binding, MysqlDefs.FIELD_TYPE_BLOB);            binding.value = x;            binding.isNull = false;            binding.isLongData = false;        }    }    /**     * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader,     *      int)     */    public void setCharacterStream(int parameterIndex, Reader reader, int length)        throws SQLException {        checkClosed();        if (reader == null) {            setNull(parameterIndex, java.sql.Types.BINARY);        } else {            BindValue binding = getBinding(parameterIndex, true);            setType(binding, MysqlDefs.FIELD_TYPE_BLOB);            binding.value = reader;            binding.isNull = false;            binding.isLongData = true;            if (this.connection.getUseStreamLengthsInPrepStmts()) {                binding.bindLength = length;            } else {                binding.bindLength = -1;            }            serverLongData(parameterIndex, binding);        }    }    /**     * @see java.sql.PreparedStatement#setClob(int, java.sql.Clob)     */    public void setClob(int parameterIndex, Clob x) throws SQLException {        checkClosed();        if (x == null) {            setNull(parameterIndex, java.sql.Types.BINARY);        } else {            BindValue binding = getBinding(parameterIndex, true);            setType(binding, MysqlDefs.FIELD_TYPE_BLOB);            binding.value = x.getCharacterStream();            binding.isNull = false;            binding.isLongData = true;            if (this.connection.getUseStreamLengthsInPrepStmts()) {                binding.bindLength = x.length();            } else {                binding.bindLength = -1;            }            serverLongData(parameterIndex, binding);        }    }    /**     * Set a parameter to a java.sql.Date value.  The driver converts this to a     * SQL DATE value when it sends it to the database.     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @param cal the calendar to interpret the date with     *     * @exception SQLException if a database-access error occurs.     */    public void setDate(int parameterIndex, Date x, Calendar cal)        throws SQLException {        if (x == null) {            setNull(parameterIndex, java.sql.Types.DATE);        } else {            BindValue binding = getBinding(parameterIndex, false);            setType(binding, MysqlDefs.FIELD_TYPE_DATE);            binding.value = x;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -