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

📄 serverpreparedstatement.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			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 SQLError.createSQLException("'" + 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 SQLError.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, null, this.connection.getDefaultTimeZone(), 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, 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	 *            the parameter value	 * @param tz	 *            the timezone to use	 * 	 * @throws SQLException	 *             if a database access error occurs	 */	public void setTimeInternal(int parameterIndex, java.sql.Time x,			Calendar targetCalendar,			TimeZone tz, boolean rollForward) throws SQLException {		if (x == null) {			setNull(parameterIndex, java.sql.Types.TIME);		} else {			BindValue binding = getBinding(parameterIndex, false);			setType(binding, MysqlDefs.FIELD_TYPE_TIME);			if (!this.useLegacyDatetimeCode) {				binding.value = x;			} else {				Calendar sessionCalendar = getCalendarInstanceForSessionOrNew();								synchronized (sessionCalendar) {					binding.value = TimeUtil.changeTimezone(this.connection, 							sessionCalendar,							targetCalendar,							x, tz,							this.connection.getServerTimezoneTZ(), 							rollForward);				}			}						binding.isNull = false;			binding.isLongData = false;		}	}	/**	 * Set a parameter to a java.sql.Timestamp value. The driver converts this	 * to a SQL TIMESTAMP value when it sends it to the database.	 * 	 * @param parameterIndex	 *            the first parameter is 1, the second is 2, ...	 * @param x	 *            the parameter value	 * 	 * @throws SQLException	 *             if a database-access error occurs.	 */	public void setTimestamp(int parameterIndex, java.sql.Timestamp x)			throws SQLException {		setTimestampInternal(parameterIndex, x, null, this.connection.getDefaultTimeZone(), false);	}	/**	 * Set a parameter to a java.sql.Timestamp value. The driver converts this	 * to a SQL TIMESTAMP 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 timezone to use	 * 	 * @throws SQLException	 *             if a database-access error occurs.	 */	public void setTimestamp(int parameterIndex, java.sql.Timestamp x,			Calendar cal) throws SQLException {		setTimestampInternal(parameterIndex, x, cal, cal.getTimeZone(), true);	}	protected void setTimestampInternal(int parameterIndex,			java.sql.Timestamp x, Calendar targetCalendar,			TimeZone tz, boolean rollForward)			throws SQLException {		if (x == null) {			setNull(parameterIndex, java.sql.Types.TIMESTAMP);		} else {			BindValue binding = getBinding(parameterIndex, false);			setType(binding, MysqlDefs.FIELD_TYPE_DATETIME);			if (!this.useLegacyDatetimeCode) {				binding.value = x;			} else {				Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ?						this.connection.getUtcCalendar() : 							getCalendarInstanceForSessionOrNew();								synchronized (sessionCalendar) {					binding.value = TimeUtil.changeTimezone(this.connection, 							sessionCalendar,							targetCalendar,							x, tz,							this.connection.getServerTimezoneTZ(), 							rollForward);				}								binding.isNull = false;				binding.isLongData = false;			}		}	}	protected void setType(BindValue oldValue, int bufferType) {		if (oldValue.bufferType != bufferType) {			this.sendTypesToServer = true;		}		oldValue.bufferType = bufferType;	}	/**	 * DOCUMENT ME!	 * 	 * @param parameterIndex	 *            DOCUMENT ME!	 * @param x	 *            DOCUMENT ME!	 * @param length	 *            DOCUMENT ME!	 * 	 * @throws SQLException	 *             DOCUMENT ME!	 * @throws NotImplemented	 *             DOCUMENT ME!	 * 	 * @see java.sql.PreparedStatement#setUnicodeStream(int,	 *      java.io.InputStream, int)	 * @deprecated	 */	public void setUnicodeStream(int parameterIndex, InputStream x, int length)			throws SQLException {		checkClosed();		throw SQLError.notImplemented();	}	/**	 * @see java.sql.PreparedStatement#setURL(int, java.net.URL)	 */	public void setURL(int parameterIndex, URL x) throws SQLException {		checkClosed();		setString(parameterIndex, x.toString());	}	/**	 * Method storeBinding.	 * 	 * @param packet	 * @param bindValue	 * @param mysql	 *            DOCUMENT ME!	 * 	 * @throws SQLException	 *             DOCUMENT ME!	 */	private void storeBinding(Buffer packet, BindValue bindValue, MysqlIO mysql)			throws SQLException {		try {			Object value = bindValue.value;			//			// Handle primitives first			//			switch (bindValue.bufferType) {			case MysqlDefs.FIELD_TYPE_TINY:				packet.writeByte(bindValue.byteBinding);				return;			case MysqlDefs.FIELD_TYPE_SHORT:				packet.ensureCapacity(2);				packet.writeInt(bindValue.shortBinding);				return;			case MysqlDefs.FIELD_TYPE_LONG:				packet.ensureCapacity(4);				packet.writeLong(bindValue.intBinding);				return;			case MysqlDefs.FIELD_TYPE_LONGLONG:				packet.ensureCapacity(8);				packet.writeLongLong(bindValue.longBinding);				return;			case MysqlDefs.FIELD_TYPE_FLOAT:				packet.ensureCapacity(4);				packet.writeFloat(bindValue.floatBinding);				return;			case MysqlDefs.FIELD_TYPE_DOUBLE:				packet.ensureCapacity(8);				packet.writeDouble(bindValue.doubleBinding);				return;			case MysqlDefs.FIELD_TYPE_TIME:				storeTime(packet, (Time) value);				return;			case MysqlDefs.FIELD_TYPE_DATE:			case MysqlDefs.FIELD_TYPE_DATETIME:			case MysqlDefs.FIELD_TYPE_TIMESTAMP:				storeDateTime(packet, (java.util.Date) value, mysql, bindValue.bufferType);				return;			case MysqlDefs.FIELD_TYPE_VAR_STRING:			case MysqlDefs.FIELD_TYPE_STRING:			case MysqlDefs.FIELD_TYPE_VARCHAR:			case MysqlDefs.FIELD_TYPE_DECIMAL:			case MysqlDefs.FIELD_TYPE_NEW_DECIMAL:				if (value instanceof byte[]) {					packet.writeLenBytes((byte[]) value);				} else if (!this.isLoadDataQuery) {					packet.writeLenString((String) value, this.charEncoding,							this.connection.getServerCharacterEncoding(),							this.charConverter, this.connection									.parserKnowsUnicode(),									this.connection);				} else {					packet.writeLenBytes(((String) value).getBytes());				}				return;			}					} catch (UnsupportedEncodingException uEE) {			throw SQLError.createSQLException(Messages					.get

⌨️ 快捷键说明

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