📄 jdbcstatement.java
字号:
* @see #getResultSet
* @see #getUpdateCount
* @see #getMoreResults
*/
public boolean execute(String sql) throws SQLException {
if(Trace.TRACE) Trace.trace();
fetchResult(sql);
if(rSet==null) {
return false;
}
return rSet.isResult();
}
/**
* Returns the current result as a <code>ResultSet</code> object.
* This method should be called only once per result.
*
* @return the current result as a ResultSet; null if the result
* is an update count or there are no more results
* @see #execute
*/
public ResultSet getResultSet() {
if(Trace.TRACE) Trace.trace();
return rSet;
}
/**
* Returns the current result as an update count;
* if the result is a ResultSet 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 it is a
* ResultSet or there are no more results
* @see #execute
*/
public int getUpdateCount() {
if(rSet==null) {
return -1;
}
return rSet.getUpdateCount();
}
/**
* Moves to a Statement's next result. It returns true if
* this result is a ResultSet. This method also implicitly
* closes any current ResultSet obtained with getResultSet.
*
* There are no more results when (!getMoreResults() &&
* (getUpdateCount() == -1)
* <P><font color="#009900">
* Hypersonic SQL currently does not support multiple ResultSets.
* </font><P>
* @return true if the next result is a ResultSet; false if it is
* an update count or there are no more results
* @see #execute
*/
public boolean getMoreResults() {
if(Trace.TRACE) Trace.trace();
return false;
}
/**
* JDBC 2.0
*
* Gives the driver 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.
* <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.
* @param direction the initial direction for processing rows
* @exception 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
*/
//#ifdef JAVA2
public void setFetchDirection(int direction) throws SQLException {
if(Trace.TRACE) Trace.trace();
if(direction!=ResultSet.FETCH_FORWARD) {
throw Trace.error(Trace.FUNCTION_NOT_SUPPORTED);
}
}
//#endif JAVA2
/**
* JDBC 2.0
*
* 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.
*
* @return the default fetch direction for result sets generated
* from this <code>Statement</code> object
*/
//#ifdef JAVA2
public int getFetchDirection() {
if(Trace.TRACE) Trace.trace();
return ResultSet.FETCH_FORWARD;
}
//#endif JAVA2
/**
* JDBC 2.0
*
* 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.
*
* @param rows the number of rows to fetch
* condition 0 <= rows <= this.getMaxRows() is not satisfied.
*/
//#ifdef JAVA2
public void setFetchSize(int rows) {
if(Trace.TRACE) Trace.trace();
}
//#endif JAVA2
/**
* JDBC 2.0
*
* Retrieves the number of result set rows that is the default
* fetch size for result sets
* 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.
* @return the default fetch size for result sets generated
* from this <code>Statement</code> object
*/
//#ifdef JAVA2
public int getFetchSize() {
if(Trace.TRACE) Trace.trace();
return 1;
}
//#endif JAVA2
/**
* JDBC 2.0
*
* Retrieves the result set concurrency.
*/
//#ifdef JAVA2
public int getResultSetConcurrency() {
if(Trace.TRACE) Trace.trace();
return ResultSet.CONCUR_READ_ONLY;
}
//#endif JAVA2
/**
* JDBC 2.0
*
* Determine the result set type.
*/
//#ifdef JAVA2
public int getResultSetType() {
if(Trace.TRACE) Trace.trace();
return ResultSet.TYPE_FORWARD_ONLY;
}
//#endif JAVA2
/**
* JDBC 2.0
*
* Adds a SQL command to the current batch of commmands for the statement.
* This method is optional.
* <P><font color="#009900">
* Hypersonic SQL currently does not support this feature because there is
* no performance win in using batches.
* </font><P>
* @param sql typically this is a static SQL INSERT or UPDATE statement
* @exception SQLException if a database access error occurs, or the
* driver does not support batch statements
*/
//#ifdef JAVA2
public void addBatch(String sql) throws SQLException {
if(Trace.TRACE) Trace.trace();
// todo
throw Trace.error(Trace.FUNCTION_NOT_SUPPORTED);
}
//#endif JAVA2
/**
* JDBC 2.0
*
* Makes the set of commands in the current batch empty.
* This method is optional.
*
* @exception SQLException if a database access error occurs or the
* driver does not support batch statements
*/
//#ifdef JAVA2
public void clearBatch() throws SQLException {
if(Trace.TRACE) Trace.trace();
throw Trace.error(Trace.FUNCTION_NOT_SUPPORTED);
}
//#endif JAVA2
/**
* JDBC 2.0
*
* Submits a batch of commands to the database for execution.
* This method is optional.
*
* @return an array of update counts containing one element for each
* command in the batch. The array is ordered according
* to the order in which commands were inserted into the batch.
* @exception SQLException if a database access error occurs or the
* driver does not support batch statements
*/
//#ifdef JAVA2
public int[] executeBatch() throws SQLException {
if(Trace.TRACE) Trace.trace();
// todo
throw Trace.error(Trace.FUNCTION_NOT_SUPPORTED);
}
//#endif JAVA2
/**
* JDBC 2.0
*
* Returns the <code>Connection</code> object
* that produced this <code>Statement</code> object.
* @return the connection that produced this statement
*/
//#ifdef JAVA2
public Connection getConnection() {
if(Trace.TRACE) Trace.trace();
return cConnection;
}
//#endif JAVA2
jdbcStatement(jdbcConnection c) {
bEscapeProcessing=true;
cConnection=c;
}
private void fetchResult(String sql) throws SQLException {
if(bEscapeProcessing) {
sql=cConnection.nativeSQL(sql);
}
closeOldResult();
if(iMaxRows==0) {
rSet=cConnection.execute(sql);
} else {
try {
sql="SET MAXROWS "+iMaxRows+";"+sql;
rSet=cConnection.execute(sql);
cConnection.execute("SET MAXROWS 0");
} catch(SQLException e) {
cConnection.execute("SET MAXROWS 0");
throw e;
}
}
}
private void closeOldResult() {
// this is necessary to conform the JDBC standard
if(rSet!=null) {
rSet.close();
rSet=null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -