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

📄 preparedstatement.java

📁 mysql的jdbc驱动
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
					.indexOf('W') != -1);			if ((!atEnd && !finishesAtDate) || (containsEnd)) {				vecRemovelist.add(v);			}		}		size = vecRemovelist.size();		for (int i = 0; i < size; i++) {			vec.remove(vecRemovelist.get(i));		}		vecRemovelist.clear();		v = (Object[]) vec.get(0); // might throw exception		StringBuffer format = (StringBuffer) v[1];		format.setLength(format.length() - 1);		return format.toString();	}	/*	 * (non-Javadoc)	 * 	 * @see java.sql.Statement#getGeneratedKeys()	 */	public synchronized java.sql.ResultSet getGeneratedKeys()			throws SQLException {		if (this.batchedGeneratedKeys == null) {			return super.getGeneratedKeys();		}		Field[] fields = new Field[1];		fields[0] = new Field("", "GENERATED_KEY", Types.BIGINT, 17); //$NON-NLS-1$ //$NON-NLS-2$		fields[0].setConnection(this.connection);				return new com.mysql.jdbc.ResultSet(this.currentCatalog, fields,				new RowDataStatic(this.batchedGeneratedKeys), this.connection,				this);	}	/**	 * The number, types and properties of a ResultSet's columns are provided by	 * the getMetaData method.	 * 	 * @return the description of a ResultSet's columns	 * 	 * @exception SQLException	 *                if a database-access error occurs.	 */	public synchronized java.sql.ResultSetMetaData getMetaData()			throws SQLException {		if (!StringUtils.startsWithIgnoreCaseAndNonAlphaNumeric(				this.originalSql, "SELECT")) {			return null;		}		PreparedStatement mdStmt = null;		java.sql.ResultSet mdRs = null;		if (this.pstmtResultMetaData == null) {			try {				mdStmt = new PreparedStatement(this.connection,						this.originalSql, this.currentCatalog, this.parseInfo);				mdStmt.setMaxRows(0);				int paramCount = this.parameterValues.length;				for (int i = 1; i <= paramCount; i++) {					mdStmt.setString(i, ""); //$NON-NLS-1$				}				boolean hadResults = mdStmt.execute();				if (hadResults) {					mdRs = mdStmt.getResultSet();					this.pstmtResultMetaData = mdRs.getMetaData();				} else {					this.pstmtResultMetaData = new ResultSetMetaData(							new Field[0]);				}			} finally {				SQLException sqlExRethrow = null;				if (mdRs != null) {					try {						mdRs.close();					} catch (SQLException sqlEx) {						sqlExRethrow = sqlEx;					}					mdRs = null;				}				if (mdStmt != null) {					try {						mdStmt.close();					} catch (SQLException sqlEx) {						sqlExRethrow = sqlEx;					}					mdStmt = null;				}				if (sqlExRethrow != null) {					throw sqlExRethrow;				}			}		}		return this.pstmtResultMetaData;	}	/**	 * @see PreparedStatement#getParameterMetaData()	 */	public synchronized ParameterMetaData getParameterMetaData() 		throws SQLException {		if (this.parameterMetaData == null) {			this.parameterMetaData = new MysqlParameterMetadata(					null, this.parameterCount);		}				return this.parameterMetaData;	}	ParseInfo getParseInfo() {		return this.parseInfo;	}	private final char getSuccessor(char c, int n) {		return ((c == 'y') && (n == 2)) ? 'X'				: (((c == 'y') && (n < 4)) ? 'y'						: ((c == 'y') ? 'M'								: (((c == 'M') && (n == 2)) ? 'Y'										: (((c == 'M') && (n < 3)) ? 'M'												: ((c == 'M') ? 'd'														: (((c == 'd') && (n < 2)) ? 'd'																: ((c == 'd') ? 'H'																		: (((c == 'H') && (n < 2)) ? 'H'																				: ((c == 'H') ? 'm'																						: (((c == 'm') && (n < 2)) ? 'm'																								: ((c == 'm') ? 's'																										: (((c == 's') && (n < 2)) ? 's'																												: 'W'))))))))))));	}	/**	 * Used to escape binary data with hex for mb charsets	 * 	 * @param buf	 * @param packet	 * @param size	 * @throws SQLException	 */	private final void hexEscapeBlock(byte[] buf, Buffer packet, int size)			throws SQLException {		for (int i = 0; i < size; i++) {			byte b = buf[i];			int lowBits = (b & 0xff) / 16;			int highBits = (b & 0xff) % 16;			packet.writeByte(HEX_DIGITS[lowBits]);			packet.writeByte(HEX_DIGITS[highBits]);		}	}	private void initializeFromParseInfo() throws SQLException {		this.staticSqlStrings = this.parseInfo.staticSql;		this.hasLimitClause = this.parseInfo.foundLimitClause;		this.isLoadDataQuery = this.parseInfo.foundLoadData;		this.firstCharOfStmt = this.parseInfo.firstStmtChar;		this.parameterCount = this.staticSqlStrings.length - 1;		this.parameterValues = new byte[this.parameterCount][];		this.parameterStreams = new InputStream[this.parameterCount];		this.isStream = new boolean[this.parameterCount];		this.streamLengths = new int[this.parameterCount];		this.isNull = new boolean[this.parameterCount];		clearParameters();		for (int j = 0; j < this.parameterCount; j++) {			this.isStream[j] = false;		}	}	boolean isNull(int paramIndex) {		return this.isNull[paramIndex];	}	private final int readblock(InputStream i, byte[] b) throws SQLException {		try {			return i.read(b);		} catch (Throwable E) {			throw new SQLException(Messages.getString("PreparedStatement.56") //$NON-NLS-1$					+ E.getClass().getName(), SQLError.SQL_STATE_GENERAL_ERROR);		}	}	private final int readblock(InputStream i, byte[] b, int length)			throws SQLException {		try {			int lengthToRead = length;			if (lengthToRead > b.length) {				lengthToRead = b.length;			}			return i.read(b, 0, lengthToRead);		} catch (Throwable E) {			throw new SQLException(Messages.getString("PreparedStatement.55") //$NON-NLS-1$					+ E.getClass().getName(), SQLError.SQL_STATE_GENERAL_ERROR);		}	}	/**	 * Closes this statement, releasing all resources	 * 	 * @param calledExplicitly	 *            was this called by close()?	 * 	 * @throws SQLException	 *             if an error occurs	 */	protected void realClose(boolean calledExplicitly) throws SQLException {		if (this.useUsageAdvisor) {			if (this.numberOfExecutions <= 1) {				String message = Messages.getString("PreparedStatement.43"); //$NON-NLS-1$				this.eventSink.consumeEvent(new ProfilerEvent(						ProfilerEvent.TYPE_WARN, "", this.currentCatalog, //$NON-NLS-1$						this.connection.getId(), this.getId(), -1, System								.currentTimeMillis(), 0, null,						this.pointOfOrigin, message));			}		}		super.realClose(calledExplicitly);		this.dbmd = null;		this.originalSql = null;		this.staticSqlStrings = null;		this.parameterValues = null;		this.parameterStreams = null;		this.isStream = null;		this.streamLengths = null;		this.isNull = null;		this.streamConvertBuf = null;	}	/**	 * JDBC 2.0 Set an Array parameter.	 * 	 * @param i	 *            the first parameter is 1, the second is 2, ...	 * @param x	 *            an object representing an SQL array	 * 	 * @throws SQLException	 *             because this method is not implemented.	 * @throws NotImplemented	 *             DOCUMENT ME!	 */	public void setArray(int i, Array x) throws SQLException {		throw new NotImplemented();	}	/**	 * When a very large ASCII value is input to a LONGVARCHAR parameter, it may	 * be more practical to send it via a java.io.InputStream. JDBC will read	 * the data from the stream as needed, until it reaches end-of-file. The	 * JDBC driver will do any necessary conversion from ASCII to the database	 * char format.	 * 	 * <P>	 * <B>Note:</B> This stream object can either be a standard Java stream	 * object or your own subclass that implements the standard interface.	 * </p>	 * 	 * @param parameterIndex	 *            the first parameter is 1...	 * @param x	 *            the parameter value	 * @param length	 *            the number of bytes in the stream	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public synchronized void setAsciiStream(int parameterIndex, InputStream x,			int length) throws SQLException {		if (x == null) {			setNull(parameterIndex, java.sql.Types.VARCHAR);		} else {			setBinaryStream(parameterIndex, x, length);		}	}	/**	 * Set a parameter to a java.math.BigDecimal value. The driver converts this	 * to a SQL NUMERIC value when it sends it to the database.	 * 	 * @param parameterIndex	 *            the first parameter is 1...	 * @param x	 *            the parameter value	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public void setBigDecimal(int parameterIndex, BigDecimal x)			throws SQLException {		if (x == null) {			setNull(parameterIndex, java.sql.Types.DECIMAL);		} else {			setInternal(parameterIndex, StringUtils					.fixDecimalExponent(StringUtils.consistentToString(x)));		}	}	/**	 * When a very large binary value is input to a LONGVARBINARY parameter, it	 * may be more practical to send it via a java.io.InputStream. JDBC will	 * read the data from the stream as needed, until it reaches end-of-file.	 * 	 * <P>	 * <B>Note:</B> This stream object can either be a standard Java stream	 * object or your own subclass that implements the standard interface.	 * </p>	 * 	 * @param parameterIndex	 *            the first parameter is 1...	 * @param x	 *            the parameter value	 * @param length	 *            the number of bytes to read from the stream (ignored)	 * 	 * @throws SQLException	 *             if a database access error occurs	 */	public void setBinaryStream(int parameterIndex, InputStream x, int length)			throws SQLException {		if (x == null) {			setNull(parameterIndex, java.sql.Types.BINARY);		} else {			if ((parameterIndex < 1)					|| (parameterIndex > this.staticSqlStrings.length)) {				throw new SQLException(						Messages.getString("PreparedStatement.2") //$NON-NLS-1$								+ parameterIndex								+ Messages.getString("PreparedStatement.3") + this.staticSqlStrings.length + Messages.getString("PreparedStatement.4"), //$NON-NLS-1$ //$NON-NLS-2$						SQLError.SQL_STATE_ILLEGAL_ARGUMENT);			}			this.parameterStreams[parameterIndex - 1] = x;			this.isStream[parameterIndex - 1] = true;			this.streamLengths[parameterIndex - 1] = length;			this.isNull[parameterIndex - 1] = false;		}	}	/**	 * JDBC 2.0 Set a BLOB parameter.	 * 	 * @param i	 *            the first parameter is 1, the second is 2, ...	 * @param x	 *            an object representing a BLOB	 * 	 * @throws SQLException	 *             if a database error occurs	 */	public void setBlob(int i, java.sql.Blob x) throws SQLException {		if (x == null) {			setNull(i, Types.BLOB);		} else {			ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();			bytesOut.write('\'');			escapeblockFast(x.getBytes(1, (int) x.length()), bytesOut, (int) x					.length());			bytesOut.write('\'');			setInternal(i, bytesOut.toByteArray());		}	}	/**	 * Set a parameter to a Java boolean value. The driver converts this to a	 * SQL BIT value when it sends it to the database.	 * 	 * @param parameterIndex	 *            the first parameter is 1...	 * @param x	 *            the parameter value	 * 	 * @throws SQLException	 *             if a database access error occurs	 */	public void setBoolean(int parameterIndex, boolean x) throws SQLException {		if (this.useTrueBoolean) {			setInternal(parameterIndex, x ? "'1'" : "'0'"); //$NON-NLS-1$ //$NON-NLS-2$		} else {			setInternal(parameterIndex, x ? "'t'" : "'f'"); //$NON-NLS-1$ //$NON-NLS-2$		}	}	/**	 * Set a parameter to a Java byte value. The driver converts this to a SQL	 * TINYINT value when it sends it to the database.	 * 	 * @param parameterIndex	 *            the first parameter is 1...	 * @param x	 *            the parameter value	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public void setByte(int parameterIndex, byte x) throws SQLException {		setInternal(parameterIndex, String.valueOf(x));	}	/**	 * Set a parameter to a Java array of bytes. The driver converts this to a	 * SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative	 * to the driver's limits on VARBINARYs) when it sends it to the database.	 * 	 * @param parameterIndex	 *            the first parameter is 1...	 * @param x	 *            the parameter value	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public void setBytes(int parameterIndex, byte[] x) throws SQLException {		setBytes(parameterIndex, x, true, true);	}	protected void setBytes(int parameterIndex, byte[] x,			boolean checkForIntroducer, boolean escapeForMBChars)			throws SQLException {		if (x == null) {			setNull(parameterIndex, java.sql.Types.BINARY);		} else {			String connectionEncoding = this.connection.getEncoding();			if (escapeForMBChars && this.connection.getUseUnicode()					&& connectionEncoding != null					&& CharsetMapping.isMultibyteCharset(connectionEncoding)) {				// Send as hex				ByteArrayOutputStream bOut = new ByteArrayOutputStream(						(x.length * 2) + 3);				bOut.write('x');				bOut.write('\'');				for (int i = 0; i < x.length; i++) {					int lowBits = (x[i] & 0xff) / 16;					int highBits = (x[i] & 0xff) % 16;					bOut.write(HEX_DIGITS[lowBits]);					bOut.write(HEX_DIGITS[highBits]);				}				bOut.write('\'');				setInternal(parameterIndex, bOut.toByteArray());				return;			}			// escape them			int numBytes = x.length;			int pad = 2;

⌨️ 快捷键说明

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