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

📄 statement.java

📁 开发MySql数据库的最新JDBC驱动。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * 	 * @exception SQLException	 *                if a database access error occurs (why?)	 */	public java.sql.ResultSet getResultSet() throws SQLException {		return ((this.results != null) && this.results.reallyResult()) ? (java.sql.ResultSet) this.results				: null;	}	/**	 * JDBC 2.0 Determine the result set concurrency.	 * 	 * @return CONCUR_UPDATABLE or CONCUR_READONLY	 * 	 * @throws SQLException	 *             if an error occurs	 */	public int getResultSetConcurrency() throws SQLException {		return this.resultSetConcurrency;	}	/**	 * @see Statement#getResultSetHoldability()	 */	public int getResultSetHoldability() throws SQLException {		return java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT;	}	protected ResultSet getResultSetInternal() {		return this.results;	}	/**	 * JDBC 2.0 Determine the result set type.	 * 	 * @return the ResultSet type (SCROLL_SENSITIVE or SCROLL_INSENSITIVE)	 * 	 * @throws SQLException	 *             if an error occurs.	 */	public int getResultSetType() throws SQLException {		return this.resultSetType;	}	/**	 * getUpdateCount returns the current result as an update count, if the	 * result is a ResultSet or there are no more results, -1 is returned. It	 * should only be called once per result.	 * 	 * @return the current result as an update count.	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public int getUpdateCount() throws SQLException {		if (this.results == null) {			return -1;		}		if (this.results.reallyResult()) {			return -1;		}		int truncatedUpdateCount = 0;		if (this.results.getUpdateCount() > Integer.MAX_VALUE) {			truncatedUpdateCount = Integer.MAX_VALUE;		} else {			truncatedUpdateCount = (int) this.results.getUpdateCount();		}		return truncatedUpdateCount;	}	/**	 * The first warning reported by calls on this Statement is returned. A	 * Statement's execute methods clear its java.sql.SQLWarning chain.	 * Subsequent Statement warnings will be chained to this	 * java.sql.SQLWarning.	 * 	 * <p>	 * The Warning chain is automatically cleared each time a statement is	 * (re)executed.	 * </p>	 * 	 * <p>	 * <B>Note:</B> If you are processing a ResultSet then any warnings	 * associated with ResultSet reads will be chained on the ResultSet object.	 * </p>	 * 	 * @return the first java.sql.SQLWarning or null	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public java.sql.SQLWarning getWarnings() throws SQLException {		checkClosed();		if (this.connection != null && !this.connection.isClosed()				&& this.connection.versionMeetsMinimum(4, 1, 0)) {			SQLWarning pendingWarningsFromServer = SQLError					.convertShowWarningsToSQLWarnings(this.connection);			if (this.warningChain != null) {				this.warningChain.setNextWarning(pendingWarningsFromServer);			} else {				this.warningChain = pendingWarningsFromServer;			}			return this.warningChain;		}		return this.warningChain;	}	/**	 * Closes this statement, and frees resources.	 * 	 * @param calledExplicitly	 *            was this called from close()?	 * 	 * @throws SQLException	 *             if an error occurs	 */	protected void realClose(boolean calledExplicitly, boolean closeOpenResults)			throws SQLException {		if (this.isClosed) {			return;		}		if (this.useUsageAdvisor) {			if (!calledExplicitly) {				String message = Messages.getString("Statement.63") //$NON-NLS-1$						+ Messages.getString("Statement.64"); //$NON-NLS-1$				this.eventSink.consumeEvent(new ProfilerEvent(						ProfilerEvent.TYPE_WARN,						"", //$NON-NLS-1$						this.currentCatalog, this.connectionId, this.getId(),						-1, System.currentTimeMillis(), 0,						Constants.MILLIS_I18N, null, this.pointOfOrigin,						message));			}		}		if (this.results != null) {			if (closeOpenResults) {				closeOpenResults = !this.holdResultsOpenOverClose;			}			if (closeOpenResults && this.connection != null					&& !this.connection.getHoldResultsOpenOverStatementClose()) {				try {					this.results.close();				} catch (Exception ex) {					;				}				this.closeAllOpenResults();			}		}		if (this.connection != null) {			if (this.maxRowsChanged) {				this.connection.unsetMaxRows(this);			}			if (!this.connection.getDontTrackOpenResources()) {				this.connection.unregisterStatement(this);			}		}		this.isClosed = true;				this.results = null;		this.connection = null;		this.warningChain = null;		this.openResults = null;		this.batchedGeneratedKeys = null;		this.cancelTimeoutMutex = null;	}	/**	 * setCursorName defines the SQL cursor name that will be used by subsequent	 * execute methods. This name can then be used in SQL positioned	 * update/delete statements to identify the current row in the ResultSet	 * generated by this statement. If a database doesn't support positioned	 * update/delete, this method is a no-op.	 * 	 * <p>	 * <b>Note:</b> This MySQL driver does not support cursors.	 * </p>	 * 	 * @param name	 *            the new cursor name	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public void setCursorName(String name) throws SQLException {		// No-op	}	/**	 * If escape scanning is on (the default), the driver will do escape	 * substitution before sending the SQL to the database.	 * 	 * @param enable	 *            true to enable; false to disable	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public void setEscapeProcessing(boolean enable)			throws SQLException {		this.doEscapeProcessing = enable;	}	/**	 * JDBC 2.0 Give a hint as to the direction in which the rows in a result	 * set will be processed. The hint applies only to result sets created using	 * this Statement object. The default value is ResultSet.FETCH_FORWARD.	 * 	 * @param direction	 *            the initial direction for processing rows	 * 	 * @exception SQLException	 *                if a database-access error occurs or direction is not one	 *                of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or	 *                ResultSet.FETCH_UNKNOWN	 */	public void setFetchDirection(int direction) throws SQLException {		switch (direction) {		case java.sql.ResultSet.FETCH_FORWARD:		case java.sql.ResultSet.FETCH_REVERSE:		case java.sql.ResultSet.FETCH_UNKNOWN:			break;		default:			throw SQLError.createSQLException(					Messages.getString("Statement.5"), //$NON-NLS-1$					SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$		}	}	/**	 * JDBC 2.0 Give the JDBC driver a hint as to the number of rows that should	 * be fetched from the database when more rows are needed. The number of	 * rows specified only affects result sets created using this statement. If	 * the value specified is zero, then the hint is ignored. The default value	 * is zero.	 * 	 * @param rows	 *            the number of rows to fetch	 * 	 * @exception SQLException	 *                if a database-access error occurs, or the condition 0	 *                &lt;= rows &lt;= this.getMaxRows() is not satisfied.	 */	public void setFetchSize(int rows) throws SQLException {		if (((rows < 0) && (rows != Integer.MIN_VALUE))				|| ((this.maxRows != 0) && (this.maxRows != -1) && (rows > this						.getMaxRows()))) {			throw SQLError.createSQLException(					Messages.getString("Statement.7"), //$NON-NLS-1$					SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ //$NON-NLS-2$		}		this.fetchSize = rows;	}	protected void setHoldResultsOpenOverClose(boolean holdResultsOpenOverClose) {		this.holdResultsOpenOverClose = holdResultsOpenOverClose;	}	/**	 * Sets the maxFieldSize	 * 	 * @param max	 *            the new max column size limit; zero means unlimited	 * 	 * @exception SQLException	 *                if size exceeds buffer size	 */	public void setMaxFieldSize(int max) throws SQLException {		if (max < 0) {			throw SQLError.createSQLException(Messages					.getString("Statement.11"), //$NON-NLS-1$					SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$		}		int maxBuf = (this.connection != null) ? this.connection				.getMaxAllowedPacket() : MysqlIO.getMaxBuf();		if (max > maxBuf) {			throw SQLError.createSQLException(Messages.getString(					"Statement.13", //$NON-NLS-1$					new Object[] { new Long(maxBuf) }), //$NON-NLS-1$					SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$		}		this.maxFieldSize = max;	}	/**	 * Set the maximum number of rows	 * 	 * @param max	 *            the new max rows limit; zero means unlimited	 * 	 * @exception SQLException	 *                if a database access error occurs	 * 	 * @see getMaxRows	 */	public void setMaxRows(int max) throws SQLException {		if ((max > MysqlDefs.MAX_ROWS) || (max < 0)) {			throw SQLError					.createSQLException(							Messages.getString("Statement.15") + max //$NON-NLS-1$									+ " > " //$NON-NLS-1$ //$NON-NLS-2$									+ MysqlDefs.MAX_ROWS + ".", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ //$NON-NLS-2$		}		if (max == 0) {			max = -1;		}		this.maxRows = max;		this.maxRowsChanged = true;		if (this.maxRows == -1) {			this.connection.unsetMaxRows(this);			this.maxRowsChanged = false;		} else {			// Most people don't use setMaxRows()			// so don't penalize them			// with the extra query it takes			// to do it efficiently unless we need			// to.			this.connection.maxRowsChanged(this);		}	}	/**	 * Sets the queryTimeout limit	 * 	 * @param seconds -	 *            the new query timeout limit in seconds	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public void setQueryTimeout(int seconds) throws SQLException {		if (seconds < 0) {			throw SQLError.createSQLException(Messages					.getString("Statement.21"), //$NON-NLS-1$					SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$		}		this.timeoutInMillis = seconds * 1000;	}	/**	 * Sets the concurrency for result sets generated by this statement	 * 	 * @param concurrencyFlag	 *            DOCUMENT ME!	 */	void setResultSetConcurrency(int concurrencyFlag) {		this.resultSetConcurrency = concurrencyFlag;	}	/**	 * Sets the result set type for result sets generated by this statement	 * 	 * @param typeFlag	 *            DOCUMENT ME!	 */	void setResultSetType(int typeFlag) {		this.resultSetType = typeFlag;	}	protected void getBatchedGeneratedKeys(java.sql.Statement batchedStatement) throws SQLException {		if (this.retrieveGeneratedKeys) {			java.sql.ResultSet rs = null;				try {				rs = batchedStatement.getGeneratedKeys();					while (rs.next()) {					this.batchedGeneratedKeys							.add(new byte[][] { rs.getBytes(1) });				}			} finally {				if (rs != null) {					rs.close();				}			}		}	}		protected void getBatchedGeneratedKeys() throws SQLException {		if (this.retrieveGeneratedKeys) {			java.sql.ResultSet rs = null;				try {				rs = getGeneratedKeysInternal();					while (rs.next()) {					this.batchedGeneratedKeys							.add(new byte[][] { rs.getBytes(1) });				}			} finally {				if (rs != null) {					rs.close();				}			}		}	}		/**	 * @return	 */	private boolean useServerFetch() throws SQLException {		return this.connection.isCursorFetchEnabled() && this.fetchSize > 0				&& this.resultSetConcurrency == ResultSet.CONCUR_READ_ONLY				&& this.resultSetType == ResultSet.TYPE_FORWARD_ONLY;	}	protected int findStartOfStatement(String sql) {		int statementStartPos = 0;				if (StringUtils.startsWithIgnoreCaseAndWs(sql, "/*")) {			statementStartPos = sql.indexOf("*/");						if (statementStartPos == -1) {				statementStartPos = 0;			} else {				statementStartPos += 2;			}		} else if (StringUtils.startsWithIgnoreCaseAndWs(sql, "--")			|| StringUtils.startsWithIgnoreCaseAndWs(sql, "#")) {			statementStartPos = sql.indexOf('\n');						if (statementStartPos == -1) {				statementStartPos = sql.indexOf('\r');								if (statementStartPos == -1) {					statementStartPos = 0;				}			}		}				return statementStartPos;	}}

⌨️ 快捷键说明

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