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

📄 monetstatement.java

📁 这个是内存数据库的客户端
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		// create a container for the result		lastResponseList = connection.new ResponseList(			fetchSize,			maxRows,			resultSetType,			resultSetConcurrency		);		// fill the header list by processing the query		lastResponseList.processQuery(sql);		return(getMoreResults());	}	public boolean execute(String sql, int autoGeneratedKeys)		throws SQLException	{		throw new SQLException("Method not supported, sorry!");	}	public boolean execute(String sql, int[] columnIndexed)		throws SQLException	{		throw new SQLException("Method not supported, sorry!");	}	public boolean execute(String sql, String[] columnNames)		throws SQLException	{		throw new SQLException("Method not supported, sorry!");	}	/**	 * Executes the given SQL statement, which returns a single ResultSet	 * object.	 *	 * @param sql an SQL statement to be sent to the database, typically a	 *        static SQL SELECT statement	 * @return a ResultSet object that contains the data produced by the given	 *         query; never null	 * @throws SQLException if a database access error occurs or the given SQL	 *         statement produces anything other than a single ResultSet object	 */	public ResultSet executeQuery(String sql) throws SQLException {		if (execute(sql) != true)			throw new SQLException("Query did not produce a result set");		return(getResultSet());	}	/**	 * Executes the given SQL statement, which may be an INSERT, UPDATE, or	 * DELETE statement or an SQL statement that returns nothing, such as an	 * SQL DDL statement.	 * <br /><br />	 * make an implementation which returns affected rows, need protocol	 * modification for that!!!	 *	 * @param sql an SQL INSERT, UPDATE or DELETE statement or an SQL statement	 *        that returns nothing	 * @return either the row count for INSERT, UPDATE  or DELETE statements, or	 *         0 for SQL statements that return nothing<br />	 *         <b>currently always returns -1 since the mapi protocol doesn't	 *         return the affected rows!!!</b>	 * @throws SQLException if a database access error occurs or the given SQL	 *         statement produces a ResultSet object	 */	public int executeUpdate(String sql) throws SQLException {		if (execute(sql) != false)			throw new SQLException("Query produced a result set");		return(getUpdateCount());	}	public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { throw new SQLException("Method not supported, sorry!"); }	public int executeUpdate(String sql, int[] columnIndexed) throws SQLException { throw new SQLException("Method not supported, sorry!"); }	public int executeUpdate(String sql, String[] columnNames) throws SQLException { throw new SQLException("Method not supported, sorry!"); }	/**	 * Retrieves the Connection object that produced this Statement object.	 *	 * @return the connection that produced this statement	 */	public Connection getConnection() {		return(connection);	}	/**	 * Retrieves the direction for fetching rows from database tables that is	 * the default for result sets generated from this Statement object. If	 * this Statement object has not set a fetch direction by calling the	 * method setFetchDirection, the return value is ResultSet.FETCH_FORWARD.	 *	 * @return the default fetch direction for result sets generated from this	 *         Statement object	 */	public int getFetchDirection() {		return(fetchDirection);	}	/**	 * Retrieves the number of result set rows that is the default fetch size	 * for ResultSet objects generated from this Statement object. If this	 * Statement object has not set a fetch size by calling the method	 * setFetchSize, or the method setFetchSize was called as such to let	 * the driver ignore the hint, 0 is returned.	 *	 * @return the default fetch size for result sets generated from this	 *         Statement object	 */	public int getFetchSize() {		return(fetchSize);	}	public ResultSet getGeneratedKeys() throws SQLException { throw new SQLException("Method not supported, sorry!"); }	public int getMaxFieldSize() throws SQLException { throw new SQLException("Method not supported, sorry!"); }	/**	 * Retrieves the maximum number of rows that a ResultSet object produced by	 * this Statement object can contain. If this limit is exceeded, the excess	 * rows are silently dropped.	 *	 * @return the current maximum number of rows for a ResultSet object	 *         produced by this Statement object; zero means there is no limit	 */	public int getMaxRows() {		return(maxRows);	}	/**	 * Moves to this Statement object's next result, returns true if it is a	 * ResultSet object, and implicitly closes any current ResultSet object(s)	 * obtained with the method getResultSet.	 * <br /><br />	 * There are no more results when the following is true:<br />	 * (!getMoreResults() && (getUpdateCount() == -1)	 *	 * @return true if the next result is a ResultSet object; false if it is	 *              an update count or there are no more results	 * @throws SQLException if a database access error occurs	 * @see #getMoreResults(int current)	 */	public boolean getMoreResults() throws SQLException {		return(getMoreResults(CLOSE_ALL_RESULTS));	}	/**	 * Moves to this Statement object's next result, deals with any current	 * ResultSet object(s) according to the instructions specified by the given	 * flag, and returns true if the next result is a ResultSet object.	 * <br /><br />	 * There are no more results when the following is true:<br />	 * (!getMoreResults() && (getUpdateCount() == -1)	 *	 * @param current one of the following Statement constants indicating what	 *                should happen to current ResultSet objects obtained using	 *                the method getResultSet: CLOSE_CURRENT_RESULT,	 *                KEEP_CURRENT_RESULT, or CLOSE_ALL_RESULTS	 * @return true if the next result is a ResultSet object; false if it is	 *              an update count or there are no more results	 * @throws SQLException if a database access error occurs	 */	public boolean getMoreResults(int current) throws SQLException {		if (current == CLOSE_CURRENT_RESULT) {			lastResponseList.closeCurrentResponse();		} else if (current == CLOSE_ALL_RESULTS) {			lastResponseList.closeCurOldResponses();		}		// we default to keep current result, which requires no action		header = lastResponseList.getNextResponse();		if (header instanceof MonetConnection.ResultSetResponse) {			return(true);		} else {			return(false);		}	}	public int getQueryTimeout() throws SQLException { throw new SQLException("Method not supported, sorry!"); }	/**	 * Retrieves the current result as a ResultSet object.  This method	 * should be called only once per result.	 *	 * @return the current result as a ResultSet object or null if the result	 *         is an update count or there are no more results	 * @throws SQLException if a database access error occurs	 */	public ResultSet getResultSet() throws SQLException{		if (header instanceof MonetConnection.ResultSetResponse) {			return(				new MonetResultSet(					this,					(MonetConnection.ResultSetResponse)header				)			);		} else {			return(null);		}	}	/**	 * Retrieves the result set concurrency for ResultSet objects generated	 * by this Statement object.	 *	 * @return either ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE	 */	public int getResultSetConcurrency() {		return(resultSetConcurrency);	}	/**	 * Retrieves the result set holdability for ResultSet objects	 * generated by this Statement object.	 *	 * @return either ResultSet.HOLD_CURSORS_OVER_COMMIT or	 *         ResultSet.CLOSE_CURSORS_AT_COMMIT	 * @throws SQLException if a database access error occurs	 */	public int getResultSetHoldability() throws SQLException {		return(ResultSet.HOLD_CURSORS_OVER_COMMIT);	}	/**	 * Retrieves the result set type for ResultSet objects generated by this	 * Statement object.	 *	 * @return one of ResultSet.TYPE_FORWARD_ONLY,	 *         ResultSet.TYPE_SCROLL_INSENSITIVE, or	 *         ResultSet.TYPE_SCROLL_SENSITIVE	 */	public int getResultSetType() {		return(resultSetType);	}	/**	 * Retrieves the current result as an update count; if the result is a	 * ResultSet object or there are no more results, -1 is returned.  This	 * method should be called only once per result.	 *	 * @return the current result as an update count; -1 if the current result	 *         is a ResultSet object or there are no more results	 * @throws SQLException if a database access error occurs	 */	public int getUpdateCount() throws SQLException {		int ret = -1;		if (header instanceof MonetConnection.AffectedRowsResponse) {			ret = ((MonetConnection.AffectedRowsResponse)header).count;		}		return(ret);	}	/**	 * Retrieves the first warning reported by calls on this Statement object.	 * If there is more than one warning, subsequent warnings will be chained to	 * the first one and can be retrieved by calling the method	 * SQLWarning.getNextWarning on the warning that was retrieved previously.	 * <br /><br />	 * This method may not be called on a closed statement; doing so will cause	 * an SQLException to be thrown.	 * <br /><br />	 * Note: Subsequent warnings will be chained to this SQLWarning.	 *	 * @return the first SQLWarning object or null if there are none	 * @throws SQLException if a database access error occurs or this method is	 *         called on a closed connection	 */	public SQLWarning getWarnings() throws SQLException {		if (closed) throw new SQLException("Cannot call on closed Statement");		// if there are no warnings, this will be null, which fits with the		// specification.		return(warnings);	}	public void setCursorName(String name) throws SQLException { throw new SQLException("Method not supported, sorry!"); }	public void setEscapeProcessing(boolean enable) throws SQLException { throw new SQLException("Method not supported, sorry!"); }	/**	 * Gives the driver a hint as to the direction in which rows will be	 * processed in ResultSet objects created using this Statement object.	 * The default value is ResultSet.FETCH_FORWARD.	 * <br /><br />	 * Note that this method sets the default fetch direction for result sets	 * generated by this Statement object. Each result set has its own methods	 * for getting and setting its own fetch direction.	 *	 * @param direction the initial direction for processing rows	 * @throws SQLException if a database access error occurs or the given	 *         direction is not one of ResultSet.FETCH_FORWARD,	 *         ResultSet.FETCH_REVERSE, or ResultSet.FETCH_UNKNOWN	 */	public void setFetchDirection(int direction) throws SQLException {		if (direction == ResultSet.FETCH_FORWARD ||		    direction == ResultSet.FETCH_REVERSE ||			direction == ResultSet.FETCH_UNKNOWN)		{			fetchDirection = direction;		} else {			throw new SQLException("Illegal direction: " + direction);		}	}	/**	 * Gives 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 affects only result sets created using this statement. If the	 * value specified is zero, then the hint is ignored.	 *	 * @param rows the number of rows to fetch	 * @throws SQLException if the condition 0 <= rows <= this.getMaxRows()	 *         is not satisfied.	 */	public void setFetchSize(int rows) throws SQLException {		if (rows >= 0 && !(getMaxRows() != 0 && rows > getMaxRows())) {			fetchSize = rows;		} else {			throw new SQLException("Illegal fetch size value: " + rows);		}	}	public void setMaxFieldSize(int max) throws SQLException { throw new SQLException("Method not supported, sorry!"); }	/**	 * Sets the limit for the maximum number of rows that any ResultSet object	 * can contain to the given number. If the limit is exceeded, the excess	 * rows are silently dropped.	 *	 * @param max the new max rows limit; zero means there is no limit	 * @throws SQLException if the condition max >= 0 is not satisfied	 */	public void setMaxRows(int max) throws SQLException {		if (max < 0) throw new SQLException("Illegal max value: " + max);		maxRows = max;	}	public void setQueryTimeout(int seconds) throws SQLException { throw new SQLException("Method not supported, sorry!"); }	//== end methods of interface Statement	protected void finalize() throws Throwable {		close();		super.finalize();	}	/**	 * Adds a warning to the pile of warnings this Statement object has. If	 * there were no warnings (or clearWarnings was called) this warning will	 * be the first, otherwise this warning will get appended to the current	 * warning.	 *	 * @param reason the warning message	 */	private void addWarning(String reason) {		if (warnings == null) {			warnings = new SQLWarning(reason);		} else {			warnings.setNextWarning(new SQLWarning(reason));		}	}}

⌨️ 快捷键说明

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