📄 jdbcstatement.java
字号:
//----------------------- Multiple Results -------------------------- /** * <!-- start generic documentation --> * Executes the given SQL statement, which may return multiple results. * In some (uncommon) situations, a single SQL statement may return * multiple result sets and/or update counts. Normally you can ignore * this unless you are (1) executing a stored procedure that you know may * return multiple results or (2) you are dynamically executing an * unknown SQL string. * <P> * The <code>execute</code> method executes an SQL statement and indicates the * form of the first result. You must then use the methods * <code>getResultSet</code> or <code>getUpdateCount</code> * to retrieve the result, and <code>getMoreResults</code> to * move to any subsequent result(s). <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @param sql any SQL statement * @return <code>true</code> if the first result is a <code>ResultSet</code> * object; <code>false</code> if it is an update count or there are * no results * @exception SQLException if a database access error occurs * @see #getResultSet * @see #getUpdateCount * @see #getMoreResults */ public boolean execute(String sql) throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); fetchResult(sql); if (rSet == null) { return false; } return rSet.isResult(); } /** * <!-- start generic documentation --> * Retrieves the current result as a <code>ResultSet</code> object. * This method should be called only once per result. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * Calling this method multiple times returns multiple references * to the same result, if any. * </span> * <!-- end release-specific documentation --> * * @return the current result as a <code>ResultSet</code> object or * <code>null</code> if the result is an update count or there are no more results * @exception SQLException if a database access error occurs * @see #execute */ public ResultSet getResultSet() throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); if ((rSet != null) && rSet.isResult()) { return rSet; } return null; } /** * <!-- start generic documentation --> * Retrieves the current result as an update count; * if the result is a <code>ResultSet</code> object or there are no more results, -1 * is returned. This method should be called only once per result. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * </span> * <!-- end release-specific documentation --> * * @return the current result as an update count; -1 if the current result is a * <code>ResultSet</code> object or there are no more results * @exception SQLException if a database access error occurs * @see #execute */ public int getUpdateCount() throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); if (rSet == null) { return -1; } return rSet.getUpdateCount(); } /** * <!-- start generic documentation --> * Moves to this <code>Statement</code> object's next result, returns * <code>true</code> if it is a <code>ResultSet</code> object, and * implicitly closes any current <code>ResultSet</code> * object(s) obtained with the method <code>getResultSet</code>. * * <P>There are no more results when the following is true: * <PRE> * <code>(!getMoreResults() && (getUpdateCount() == -1)</code> * </PRE> <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * Up to and including 1.7.1, HSQLDB does not support multiple results. <p> * * Calling this method closes the current result (if any) and always * returns <code>false</code>. * </span> * <!-- end release-specific documentation --> * * @return <code>true</code> if the next result is a <code>ResultSet</code> * object; <code>false</code> if it is an update count or there are * no more results * @exception SQLException if a database access error occurs * @see #execute */ public boolean getMoreResults() throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); if (rSet != null) { rSet.close(); rSet = null; } return false; } //--------------------------JDBC 2.0----------------------------- /** * <!-- start generic documentation --> * Gives the driver a hint as to the direction in which * rows will be processed in <code>ResultSet</code> * objects created using this <code>Statement</code> object. The * default value is <code>ResultSet.FETCH_FORWARD</code>. * <P> * Note that this method sets the default fetch direction for * result sets generated by this <code>Statement</code> object. * Each result set has its own methods for getting and setting * its own fetch direction. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * Up to and including 1.7.1, HSQLDB supports only * <code>FETCH_FORWARD</code>. <p> * * Setting any other value will throw a <CODE>SQLException</CODE>, * stating the the function is not supported. * </span> * <!-- end release-specific documentation --> * * @param direction the initial direction for processing rows * @exception SQLException if a database access error occurs * or the given direction * is not one of <code>ResultSet.FETCH_FORWARD</code>, * <code>ResultSet.FETCH_REVERSE</code>, or * <code>ResultSet.FETCH_UNKNOWN</code> <p> * * HSQLDB throws for all values except <code>FETCH_FORWARD</code> * @since JDK 1.2 (JDK 1.1.x developers: read the new overview * for jdbcStatement) * @see #getFetchDirection */ public void setFetchDirection(int direction) throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); if (direction != jdbcResultSet.FETCH_FORWARD) { throw Trace.error(Trace.FUNCTION_NOT_SUPPORTED); } } /** * <!-- start generic documentation --> * Retrieves the direction for fetching rows from * database tables that is the default for result sets * generated from this <code>Statement</code> object. * If this <code>Statement</code> object has not set * a fetch direction by calling the method <code>setFetchDirection</code>, * the return value is implementation-specific. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</B> <p> * * Up to and including 1.7.1, HSQLDB always returns FETCH_FORWARD. <p> * * </span> * <!-- end release-specific documentation --> * * @return the default fetch direction for result sets generated * from this <code>Statement</code> object * @exception SQLException if a database access error occurs * @since JDK 1.2 (JDK 1.1.x developers: read the new overview * for jdbcStatement) * @see #setFetchDirection */ public int getFetchDirection() throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); return jdbcResultSet.FETCH_FORWARD; } /** * <!-- start generic documentation --> * 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. * The default value is zero. <p> * <!-- start generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information:</b> <p> * * Up to and including HSQLDB 1.7.0, calls to this method are simply * ignored; HSQLDB always fetches a result completely as part of e * xecuting its statement. * </span> * <!-- end release-specific documentation --> * * @param rows the number of rows to fetch * @exception SQLException if a database access error occurs, or the * condition 0 <= <code>rows</code> <= <code>this.getMaxRows()</code> * is not satisfied. <p> * * HSQLDB never throws an exception, since calls to this method * are always ignored. * @since JDK 1.2 (JDK 1.1.x developers: read the new overview * for jdbcStatement) * @see #getFetchSize */ public void setFetchSize(int rows) throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); } /** * <!-- start generic documentation --> * Retrieves the number of result set rows that is the default * fetch size for <code>ResultSet</code> objects * generated from this <code>Statement</code> object. * If this <code>Statement</code> object has not set * a fetch size by calling the method <code>setFetchSize</code>, * the return value is implementation-specific. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation"> * <b>HSQLDB-Specific Information</b> <p> * * Up to and including 1.7.1, this method always returns 0. * That is, HSQLDB always decides the fetch size, that being all the * rows of a result. <p> * * </span> * <!-- end release-specific documentation --> * * @return the default fetch size for result sets generated * from this <code>Statement</code> object * @exception SQLException if a database access error occurs * @since JDK 1.2 (JDK 1.1.x developers: read the new overview * for jdbcStatement) * @see #setFetchSize */ public int getFetchSize() throws SQLException { if (Trace.TRACE) { Trace.trace(); } checkClosed(); // FIXME: fredt - changed // setFetchSize suggests that the attribute is a hint and // that zero is the "magic number" that lets the driver decide for // itself what the best fetch is. As such, we should return zero // here, since we always ignore setFetchSize and simply fetch the // result entirely. // boucherb@users 20020425 return 0; } /** * <!-- start generic documentation --> * Retrieves the result set concurrency for <code>ResultSet</code> objects * generated by this <code>Statement</code> object. <p> * <!-- end generic documentation --> * * <!-- start release-specific documentation --> * <span class="ReleaseSpecificDocumentation">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -