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

📄 statement.java

📁 开发MySql数据库的最新JDBC驱动。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		int truncatedUpdateCount = 0;		if (this.updateCount > Integer.MAX_VALUE) {			truncatedUpdateCount = Integer.MAX_VALUE;		} else {			truncatedUpdateCount = (int) this.updateCount;		}		this.lastInsertId = rs.getUpdateID();		return truncatedUpdateCount;	}	/**	 * @see Statement#executeUpdate(String, int)	 */	public int executeUpdate(String sql, int returnGeneratedKeys)			throws SQLException {		if (returnGeneratedKeys == java.sql.Statement.RETURN_GENERATED_KEYS) {			checkClosed();			Connection locallyScopedConn = this.connection;						synchronized (locallyScopedConn.getMutex()) {				// If this is a 'REPLACE' query, we need to be able to parse				// the 'info' message returned from the server to determine				// the actual number of keys generated.				boolean readInfoMsgState = locallyScopedConn						.isReadInfoMsgEnabled();				locallyScopedConn.setReadInfoMsgEnabled(true);				try {					return executeUpdate(sql);				} finally {					locallyScopedConn.setReadInfoMsgEnabled(readInfoMsgState);				}			}		}		return executeUpdate(sql);	}	/**	 * @see Statement#executeUpdate(String, int[])	 */	public int executeUpdate(String sql, int[] generatedKeyIndices)			throws SQLException {		if ((generatedKeyIndices != null) && (generatedKeyIndices.length > 0)) {			checkClosed();						Connection locallyScopedConn = this.connection;						synchronized (locallyScopedConn.getMutex()) {				// If this is a 'REPLACE' query, we need to be able to parse				// the 'info' message returned from the server to determine				// the actual number of keys generated.				boolean readInfoMsgState = locallyScopedConn						.isReadInfoMsgEnabled();				locallyScopedConn.setReadInfoMsgEnabled(true);				try {					return executeUpdate(sql);				} finally {					locallyScopedConn.setReadInfoMsgEnabled(readInfoMsgState);				}			}		}		return executeUpdate(sql);	}	/**	 * @see Statement#executeUpdate(String, String[])	 */	public int executeUpdate(String sql, String[] generatedKeyNames)			throws SQLException {		if ((generatedKeyNames != null) && (generatedKeyNames.length > 0)) {			checkClosed();			Connection locallyScopedConn = this.connection;						synchronized (locallyScopedConn.getMutex()) {				// If this is a 'REPLACE' query, we need to be able to parse				// the 'info' message returned from the server to determine				// the actual number of keys generated.				boolean readInfoMsgState = this.connection						.isReadInfoMsgEnabled();				locallyScopedConn.setReadInfoMsgEnabled(true);				try {					return executeUpdate(sql);				} finally {					locallyScopedConn.setReadInfoMsgEnabled(readInfoMsgState);				}			}		}		return executeUpdate(sql);	}	/**	 * Optimization to only use one calendar per-session, or calculate it for	 * each call, depending on user configuration	 */	protected Calendar getCalendarInstanceForSessionOrNew() {		if (this.connection != null) {			return this.connection.getCalendarInstanceForSessionOrNew();		} else {			// punt, no connection around			return new GregorianCalendar();		}	}	/**	 * JDBC 2.0 Return the Connection that produced the Statement.	 * 	 * @return the Connection that produced the Statement	 * 	 * @throws SQLException	 *             if an error occurs	 */	public java.sql.Connection getConnection() throws SQLException {		return this.connection;	}	/**	 * JDBC 2.0 Determine the fetch direction.	 * 	 * @return the default fetch direction	 * 	 * @exception SQLException	 *                if a database-access error occurs	 */	public int getFetchDirection() throws SQLException {		return java.sql.ResultSet.FETCH_FORWARD;	}	/**	 * JDBC 2.0 Determine the default fetch size.	 * 	 * @return the number of rows to fetch at a time	 * 	 * @throws SQLException	 *             if an error occurs	 */	public int getFetchSize() throws SQLException {		return this.fetchSize;	}	/**	 * DOCUMENT ME!	 * 	 * @return DOCUMENT ME!	 * 	 * @throws SQLException	 *             DOCUMENT ME!	 */	public java.sql.ResultSet getGeneratedKeys()			throws SQLException {		if (this.batchedGeneratedKeys == null) {			return getGeneratedKeysInternal();		}		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);	}		/*	 * Needed because there's no concept of super.super to get to this	 * implementation from ServerPreparedStatement when dealing with batched	 * updates.	 */	protected java.sql.ResultSet getGeneratedKeysInternal()			throws SQLException {		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);		ArrayList rowSet = new ArrayList();		long beginAt = getLastInsertID();		int numKeys = getUpdateCount();		if (this.results != null) {			String serverInfo = this.results.getServerInfo();				// 			// Only parse server info messages for 'REPLACE'			// queries			//			if ((numKeys > 0) && (this.results.getFirstCharOfQuery() == 'R')					&& (serverInfo != null) && (serverInfo.length() > 0)) {				numKeys = getRecordCountFromInfo(serverInfo);			}				if ((beginAt > 0) && (numKeys > 0)) {				for (int i = 0; i < numKeys; i++) {					byte[][] row = new byte[1][];					row[0] = Long.toString(beginAt++).getBytes();					rowSet.add(row);				}			}		}		return new com.mysql.jdbc.ResultSet(this.currentCatalog, fields,				new RowDataStatic(rowSet), this.connection, this);	}	/**	 * Returns the id used when profiling	 * 	 * @return the id used when profiling.	 */	protected int getId() {		return this.statementId;	}	/**	 * getLastInsertID returns the value of the auto_incremented key after an	 * executeQuery() or excute() call.	 * 	 * <p>	 * This gets around the un-threadsafe behavior of "select LAST_INSERT_ID()"	 * which is tied to the Connection that created this Statement, and	 * therefore could have had many INSERTS performed before one gets a chance	 * to call "select LAST_INSERT_ID()".	 * </p>	 * 	 * @return the last update ID.	 */	public long getLastInsertID() {		return this.lastInsertId;	}	/**	 * getLongUpdateCount 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.	 * 	 * <p>	 * This method returns longs as MySQL server versions newer than 3.22.4	 * return 64-bit values for update counts	 * </p>	 * 	 * @return the current update count.	 */	public long getLongUpdateCount() {		if (this.results == null) {			return -1;		}		if (this.results.reallyResult()) {			return -1;		}		return this.updateCount;	}	/**	 * The maxFieldSize limit (in bytes) is the maximum amount of data returned	 * for any column value; it only applies to BINARY, VARBINARY,	 * LONGVARBINARY, CHAR, VARCHAR and LONGVARCHAR columns. If the limit is	 * exceeded, the excess data is silently discarded.	 * 	 * @return the current max column size limit; zero means unlimited	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public int getMaxFieldSize() throws SQLException {		return this.maxFieldSize;	}	/**	 * The maxRows limit is set to limit the number of rows that any ResultSet	 * can contain. If the limit is exceeded, the excess rows are silently	 * dropped.	 * 	 * @return the current maximum row limit; zero means unlimited	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public int getMaxRows() throws SQLException {		if (this.maxRows <= 0) {			return 0;		}		return this.maxRows;	}	/**	 * getMoreResults moves to a Statement's next result. If it returns true,	 * this result is a ResulSet.	 * 	 * @return true if the next ResultSet is valid	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public boolean getMoreResults() throws SQLException {		return getMoreResults(CLOSE_CURRENT_RESULT);	}	/**	 * @see Statement#getMoreResults(int)	 */	public boolean getMoreResults(int current) throws SQLException {		if (this.results == null) {			return false;		}		ResultSet nextResultSet = this.results.getNextResultSet();		switch (current) {		case java.sql.Statement.CLOSE_CURRENT_RESULT:			if (this.results != null) {				this.results.close();				this.results.clearNextResult();			}			break;		case java.sql.Statement.CLOSE_ALL_RESULTS:			if (this.results != null) {				this.results.close();				this.results.clearNextResult();			}			closeAllOpenResults();			break;		case java.sql.Statement.KEEP_CURRENT_RESULT:			if (!this.connection.getDontTrackOpenResources()) {				this.openResults.add(this.results);			}			this.results.clearNextResult(); // nobody besides us should			// ever need this value...			break;		default:			throw SQLError.createSQLException(Messages					.getString("Statement.19"), //$NON-NLS-1$					SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$		}		this.results = nextResultSet;		if (this.results == null) {			this.updateCount = -1;			this.lastInsertId = -1;		} else if (this.results.reallyResult()) {			this.updateCount = -1;			this.lastInsertId = -1;		} else {			this.updateCount = this.results.getUpdateCount();			this.lastInsertId = this.results.getUpdateID();		}		return ((this.results != null) && this.results.reallyResult()) ? true				: false;	}	/**	 * The queryTimeout limit is the number of seconds the driver will wait for	 * a Statement to execute. If the limit is exceeded, a SQLException is	 * thrown.	 * 	 * @return the current query timeout limit in seconds; 0 = unlimited	 * 	 * @exception SQLException	 *                if a database access error occurs	 */	public int getQueryTimeout() throws SQLException {		return this.timeoutInMillis / 1000;	}	/**	 * Parses actual record count from 'info' message	 * 	 * @param serverInfo	 *            DOCUMENT ME!	 * 	 * @return DOCUMENT ME!	 */	private int getRecordCountFromInfo(String serverInfo) {		StringBuffer recordsBuf = new StringBuffer();		int recordsCount = 0;		int duplicatesCount = 0;		char c = (char) 0;		int length = serverInfo.length();		int i = 0;		for (; i < length; i++) {			c = serverInfo.charAt(i);			if (Character.isDigit(c)) {				break;			}		}		recordsBuf.append(c);		i++;		for (; i < length; i++) {			c = serverInfo.charAt(i);			if (!Character.isDigit(c)) {				break;			}			recordsBuf.append(c);		}		recordsCount = Integer.parseInt(recordsBuf.toString());		StringBuffer duplicatesBuf = new StringBuffer();		for (; i < length; i++) {			c = serverInfo.charAt(i);			if (Character.isDigit(c)) {				break;			}		}		duplicatesBuf.append(c);		i++;		for (; i < length; i++) {			c = serverInfo.charAt(i);			if (!Character.isDigit(c)) {				break;			}			duplicatesBuf.append(c);		}		duplicatesCount = Integer.parseInt(duplicatesBuf.toString());		return recordsCount - duplicatesCount;	}	/**	 * getResultSet returns the current result as a ResultSet. It should only be	 * called once per result.	 * 	 * @return the current result set; null if there are no more

⌨️ 快捷键说明

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