📄 serverpreparedstatement.java
字号:
} } private void serverResetStatement() throws SQLException { synchronized (this.connection.getMutex()) { MysqlIO mysql = this.connection.getIO(); Buffer packet = mysql.getSharedSendPacket(); packet.clear(); packet.writeByte((byte) MysqlDefs.COM_RESET_STMT); packet.writeLong(this.serverStatementId); try { mysql.sendCommand(MysqlDefs.COM_RESET_STMT, null, packet, !this.connection.versionMeetsMinimum(4, 1, 2), null); } catch (SQLException sqlEx) { throw sqlEx; } catch (Exception ex) { throw new SQLException(ex.toString(), SQLError.SQL_STATE_GENERAL_ERROR); } finally { mysql.clearInputStream(); } } } /** * @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; } } } /** * @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; } } } /** * @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; } } } /** * @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_VAR_STRING); 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; } } } /** * @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; } } } /** * 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 * * @exception SQLException * if a database-access error occurs. */ public void setDate(int parameterIndex, Date x) throws SQLException { setDate(parameterIndex, x, null); } /** * 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; binding.isNull = false; binding.isLongData = false; } } /** * @see java.sql.PreparedStatement#setDouble(int, double) */ public void setDouble(int parameterIndex, double x) throws SQLException { checkClosed(); if (!this.connection.getAllowNanAndInf() && (x == Double.POSITIVE_INFINITY || x == Double.NEGATIVE_INFINITY || Double.isNaN(x))) { throw new SQLException("'" + x + "' is not a valid numeric or approximate numeric value", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } BindValue binding = getBinding(parameterIndex, false); setType(binding, MysqlDefs.FIELD_TYPE_DOUBLE); binding.value = null; binding.doubleBinding = x; binding.isNull = false; binding.isLongData = false; } /** * @see java.sql.PreparedStatement#setFloat(int, float) */ public void setFloat(int parameterIndex, float x) throws SQLException { checkClosed(); BindValue binding = getBinding(parameterIndex, false); setType(binding, MysqlDefs.FIELD_TYPE_FLOAT); binding.value = null; binding.floatBinding = x; binding.isNull = false; binding.isLongData = false; } /** * @see java.sql.PreparedStatement#setInt(int, int) */ public void setInt(int parameterIndex, int x) throws SQLException { checkClosed(); BindValue binding = getBinding(parameterIndex, false); setType(binding, MysqlDefs.FIELD_TYPE_LONG); binding.value = null; binding.intBinding = x; binding.isNull = false; binding.isLongData = false; } /** * @see java.sql.PreparedStatement#setLong(int, long) */ public void setLong(int parameterIndex, long x) throws SQLException { checkClosed(); BindValue binding = getBinding(parameterIndex, false); setType(binding, MysqlDefs.FIELD_TYPE_LONGLONG); binding.value = null; binding.longBinding = x; binding.isNull = false; binding.isLongData = false; } /** * @see java.sql.PreparedStatement#setNull(int, int) */ public void setNull(int parameterIndex, int sqlType) throws SQLException { checkClosed(); BindValue binding = getBinding(parameterIndex, false); // // Don't re-set types, but use something if this // parameter was never specified // if (binding.bufferType == 0) { setType(binding, MysqlDefs.FIELD_TYPE_NULL); } binding.value = null; binding.isNull = true; binding.isLongData = false; } /** * @see java.sql.PreparedStatement#setNull(int, int, java.lang.String) */ public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { checkClosed(); BindValue binding = getBinding(parameterIndex, false); // // Don't re-set types, but use something if this // parameter was never specified // if (binding.bufferType == 0) { setType(binding, MysqlDefs.FIELD_TYPE_NULL); } binding.value = null; binding.isNull = true; binding.isLongData = false; } /** * @see java.sql.PreparedStatement#setRef(int, java.sql.Ref) */ public void setRef(int i, Ref x) throws SQLException { throw new NotImplemented(); } /** * @see java.sql.PreparedStatement#setShort(int, short) */ public void setShort(int parameterIndex, short x) throws SQLException { checkClosed(); BindValue binding = getBinding(parameterIndex, false); setType(binding, MysqlDefs.FIELD_TYPE_SHORT); binding.value = null; binding.shortBinding = x; binding.isNull = false; binding.isLongData = false; } /** * @see java.sql.PreparedStatement#setString(int, java.lang.String) */ public void setString(int parameterIndex, String x) throws SQLException { checkClosed(); if (x == null) { setNull(parameterIndex, java.sql.Types.CHAR); } else { BindValue binding = getBinding(parameterIndex, false); setType(binding, this.stringTypeCode); binding.value = x; binding.isNull = false; binding.isLongData = false; } } /** * Set a parameter to a java.sql.Time value. * * @param parameterIndex * the first parameter is 1...)); * @param x * the parameter value * * @throws SQLException * if a database access error occurs */ public void setTime(int parameterIndex, java.sql.Time x) throws SQLException { setTimeInternal(parameterIndex, x, TimeZone.getDefault(), false); } /** * Set a parameter to a java.sql.Time value. The driver converts this to a * SQL TIME value when it sends it to the database, using the given * timezone. * * @param parameterIndex * the first parameter is 1...)); * @param x * the parameter value * @param cal * the timezone to use * * @throws SQLException * if a database access error occurs */ public void setTime(int parameterIndex, java.sql.Time x, Calendar cal) throws SQLException { setTimeInternal(parameterIndex, x, cal.getTimeZone(), true); } /** * Set a parameter to a java.sql.Time value. The driver converts this to a * SQL TIME value when it sends it to the database, using the given * timezone. * * @param parameterIndex * the first parameter is 1...)); * @param x
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -