public interface Statement
implements Wrapper, AutoCloseable
java.sql.Statement |
Known Indirect Subclasses |
用于执行静态SQL语句并返回其生成的结果的对象。
默认情况下,每个Statement
对象只能同时打开一个ResultSet
对象。 因此,如果一个ResultSet
对象的读数与另一个ResultSet
的读数交错,则每个对象必须由不同的Statement
对象生成。 如果存在打开的对象,则Statement
接口中的所有执行方法隐式关闭该对象的当前ResultSet
对象。
也可以看看:
Constants |
|
---|---|
int |
CLOSE_ALL_RESULTS 该常数表示在调用 |
int |
CLOSE_CURRENT_RESULT 该常数指示当调用 |
int |
EXECUTE_FAILED 该常数表示在执行批处理语句时发生错误。 |
int |
KEEP_CURRENT_RESULT 当调用 |
int |
NO_GENERATED_KEYS 表示生成的密钥不应用于检索的常量。 |
int |
RETURN_GENERATED_KEYS 表示生成的密钥应该可用于检索的常量。 |
int |
SUCCESS_NO_INFO 该常量表示批处理语句已成功执行,但不影响其受影响的行数。 |
Public methods |
|
---|---|
abstract void |
addBatch(String sql) 将给定的SQL命令添加到此 |
abstract void |
cancel() 如果DBMS和驱动程序都支持中止SQL语句,则取消此 |
abstract void |
clearBatch() 清空这个 |
abstract void |
clearWarnings() 清除此 |
abstract void |
close() 立即释放此 |
abstract boolean |
execute(String sql, int autoGeneratedKeys) 执行给定的SQL语句,该语句可能会返回多个结果,并向驱动程序发出通知,指出应该使任何自动生成的密钥可用于检索。 |
abstract boolean |
execute(String sql) 执行给定的SQL语句,该语句可能会返回多个结果。 |
abstract boolean |
execute(String sql, int[] columnIndexes) 执行给定的SQL语句,该语句可能会返回多个结果,并向驱动程序发出指示给定数组中指示的自动生成的键应该可用于检索的信号。 |
abstract boolean |
execute(String sql, String[] columnNames) 执行给定的SQL语句,该语句可能会返回多个结果,并向驱动程序发出指示给定数组中指示的自动生成的键应该可用于检索的信号。 |
abstract int[] |
executeBatch() 向数据库提交一批命令以执行,如果所有命令都成功执行,则返回一组更新计数。 |
abstract ResultSet |
executeQuery(String sql) 执行给定的SQL语句,该语句返回一个 |
abstract int |
executeUpdate(String sql) 执行给定的SQL语句,这可能是 |
abstract int |
executeUpdate(String sql, String[] columnNames) 执行给定的SQL语句并向驱动程序发出指示给定数组中指示的自动生成的键应该可用于检索的信号。 |
abstract int |
executeUpdate(String sql, int[] columnIndexes) 执行给定的SQL语句并向驱动程序发出指示给定数组中指示的自动生成的键应该可用于检索的信号。 |
abstract int |
executeUpdate(String sql, int autoGeneratedKeys) 执行给定的SQL语句并通过给定的标志向驱动程序发出有关是否应该使该 |
abstract Connection |
getConnection() 检索 |
abstract int |
getFetchDirection() 检索从数据库表中提取行的方向,这是从此 |
abstract int |
getFetchSize() 检索结果集合的行数是默认为获取大小 |
abstract ResultSet |
getGeneratedKeys() 检索作为执行此 |
abstract int |
getMaxFieldSize() 检索由此 |
abstract int |
getMaxRows() 检索 |
abstract boolean |
getMoreResults(int current) 移动到此 |
abstract boolean |
getMoreResults() 移动到 |
abstract int |
getQueryTimeout() 检索驱动程序等待执行 |
abstract ResultSet |
getResultSet() 以 |
abstract int |
getResultSetConcurrency() 检索由此 |
abstract int |
getResultSetHoldability() 检索由此 |
abstract int |
getResultSetType() 检索由此 |
abstract int |
getUpdateCount() 以更新计数检索当前结果; 如果结果是 |
abstract SQLWarning |
getWarnings() 检索此 |
abstract boolean |
isClosed() 检索此 |
abstract boolean |
isPoolable() 返回一个值,指示 |
abstract void |
setCursorName(String name) 将SQL游标名称设置为给定的 |
abstract void |
setEscapeProcessing(boolean enable) 设置退出处理的开启或关闭。 |
abstract void |
setFetchDirection(int direction) 为驱动程序提供关于 |
abstract void |
setFetchSize(int rows) 当 |
abstract void |
setMaxFieldSize(int max) 设置此 |
abstract void |
setMaxRows(int max) 设置由此 |
abstract void |
setPoolable(boolean poolable) 要求将 |
abstract void |
setQueryTimeout(int seconds) 将驱动程序等待 |
Inherited methods |
|
---|---|
From interface java.sql.Wrapper
|
|
From interface java.lang.AutoCloseable
|
int CLOSE_ALL_RESULTS
该常数指示在调用 getMoreResults
时应关闭先前保持打开的所有 ResultSet
对象。
常量值:3(0x00000003)
int CLOSE_CURRENT_RESULT
当调用 getMoreResults
时,该常数指示应关闭当前的 ResultSet
对象。
常数值:1(0x00000001)
int KEEP_CURRENT_RESULT
当调用 getMoreResults
时,表示当前 ResultSet
对象不应该关闭的 getMoreResults
。
常量值:2(0x00000002)
int RETURN_GENERATED_KEYS
表示生成的密钥应该可用于检索的常量。
常数值:1(0x00000001)
int SUCCESS_NO_INFO
该常量表示批处理语句已成功执行,但不影响其受影响的行数。
常量值:-2(0xfffffffe)
void addBatch (String sql)
将给定的SQL命令添加到此Statement
对象的当前命令列表中。 该列表中的命令可以通过调用方法executeBatch
以批处理方式executeBatch
。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : typically this is a SQL INSERT or UPDATE statement |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the driver does not support batch updates, the method is called on a PreparedStatement or CallableStatement |
void cancel ()
如果DBMS和驱动程序都支持中止SQL语句,则取消此Statement
对象。 这个方法可以被一个线程用来取消另一个线程正在执行的语句。
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
void clearBatch ()
清空这个 Statement
对象的当前SQL命令列表。
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement or the driver does not support batch updates |
void clearWarnings ()
清除此Statement
对象上报告的所有警告。 在调用此方法后,方法getWarnings
将返回null
直到报告此Statement
对象的新警告。
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
void close ()
立即释放此Statement
对象的数据库和JDBC资源,而不是等待它自动关闭时发生。 一旦您完成了资源释放资源以避免捆绑数据库资源,通常是一种很好的做法。
调用已关闭的 Statement
对象上的方法 close
不起作用。
注:关闭 Statement
对象时,其当前 ResultSet
对象(如果存在)也会关闭。
Throws | |
---|---|
SQLException |
if a database access error occurs |
boolean execute (String sql, int autoGeneratedKeys)
执行给定的SQL语句,该语句可能会返回多个结果,并向驱动程序发出通知,指出应该使任何自动生成的密钥可用于检索。 如果SQL语句不是INSERT
语句,或者SQL语句能够返回自动生成的键(这些语句的列表是特定于供应商的),驱动程序将忽略此信号。
在某些(不常见)情况下,单个SQL语句可能会返回多个结果集和/或更新计数。 通常情况下,你可以忽略它,除非你(1)执行一个你知道可能返回多个结果的存储过程,或者(2)你动态地执行一个未知的SQL字符串。
execute
方法执行一条SQL语句并指示第一个结果的形式。 然后您必须使用方法getResultSet
或getUpdateCount
检索结果,并使用getMoreResults
移至任何后续结果。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : any SQL statement |
autoGeneratedKeys |
int : a constant indicating whether auto-generated keys should be made available for retrieval using the method getGeneratedKeys ; one of the following constants: Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS |
Returns | |
---|---|
boolean |
true if the first result is a ResultSet object; false if it is an update count or there are no results |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the second parameter supplied to this method is not Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS , the method is called on a PreparedStatement or CallableStatement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method with a constant of Statement.RETURN_GENERATED_KEYS |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
boolean execute (String sql)
执行给定的SQL语句,该语句可能会返回多个结果。 在某些(不常见)情况下,单个SQL语句可能会返回多个结果集和/或更新计数。 通常情况下,你可以忽略它,除非你(1)执行一个你知道可能返回多个结果的存储过程,或者(2)你动态地执行一个未知的SQL字符串。
execute
方法执行SQL语句并指示第一个结果的形式。 您必须使用方法getResultSet
或getUpdateCount
检索结果,并使用getMoreResults
移至任何后续结果。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : any SQL statement |
Returns | |
---|---|
boolean |
true if the first result is a ResultSet object; false if it is an update count or there are no results |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the method is called on a PreparedStatement or CallableStatement |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
boolean execute (String sql, int[] columnIndexes)
执行给定的SQL语句,该语句可能会返回多个结果,并向驱动程序发出指示给定数组中指示的自动生成的键应该可用于检索的信号。 此数组包含目标表中包含应该使其可用的自动生成的键的列索引。 如果SQL语句不是INSERT
语句,或者SQL语句能够返回自动生成的键(这些语句的列表是特定于供应商的),驱动程序将忽略该数组。
在某些(不常见)情况下,单个SQL语句可能会返回多个结果集和/或更新计数。 通常情况下,你可以忽略它,除非你(1)执行一个你知道可能返回多个结果的存储过程,或者(2)你动态地执行一个未知的SQL字符串。
execute
方法执行一条SQL语句并指示第一个结果的形式。 然后您必须使用方法getResultSet
或getUpdateCount
检索结果,并使用getMoreResults
移至任何后续结果。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : any SQL statement |
columnIndexes |
int : an array of the indexes of the columns in the inserted row that should be made available for retrieval by a call to the method getGeneratedKeys |
Returns | |
---|---|
boolean |
true if the first result is a ResultSet object; false if it is an update count or there are no results |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the elements in the int array passed to this method are not valid column indexes, the method is called on a PreparedStatement or CallableStatement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
boolean execute (String sql, String[] columnNames)
执行给定的SQL语句,该语句可能会返回多个结果,并向驱动程序发出指示给定数组中指示的自动生成的键应该可用于检索的信号。 此数组包含目标表中包含应该使其可用的自动生成的键的列的名称。 如果SQL语句不是INSERT
语句,或者SQL语句能够返回自动生成的键(这些语句的列表是特定于供应商的),驱动程序将忽略数组。
在某些(不常见)情况下,单个SQL语句可能会返回多个结果集和/或更新计数。 通常情况下,你可以忽略它,除非你(1)执行一个你知道可能返回多个结果的存储过程,或者(2)你动态地执行一个未知的SQL字符串。
execute
方法执行一条SQL语句并指示第一个结果的形式。 然后您必须使用方法getResultSet
或getUpdateCount
检索结果,并使用getMoreResults
移至任何后续结果。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : any SQL statement |
columnNames |
String : an array of the names of the columns in the inserted row that should be made available for retrieval by a call to the method getGeneratedKeys |
Returns | |
---|---|
boolean |
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, this method is called on a closed Statement ,the elements of the String array passed to this method are not valid column names, the method is called on a PreparedStatement or CallableStatement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
int[] executeBatch ()
向数据库提交一批命令以执行,如果所有命令都成功执行,则返回一组更新计数。 返回数组的int
元素的顺序与批次中的命令相对应,这些命令按照它们添加到批次中的顺序排序。 由方法executeBatch
返回的数组中的元素可能是以下之一:
SUCCESS_NO_INFO
-- indicates that the command was processed successfully but that the number of rows affected is unknown 如果批量更新中的某个命令无法正确执行,则此方法将引发BatchUpdateException
,并且JDBC驱动程序可能会或可能不会继续处理批处理中的其余命令。 但是,驱动程序的行为必须与特定的DBMS保持一致,要么始终继续处理命令,要么永远不会继续处理命令。 如果驱动程序在失败后继续处理,则方法BatchUpdateException.getUpdateCounts
返回的数组将包含与批处理中的命令一样多的元素,并且至少有一个元素为以下内容:
EXECUTE_FAILED
-- indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails 在Java 2 SDK Standard Edition 1.3版中修改了可能的实现和返回值,以适应在抛出 BatchUpdateException
对象后继续处理批量更新中的命令的选项。
Returns | |
---|---|
int[] |
an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch. |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement or the driver does not support batch statements. Throws BatchUpdateException (a subclass of SQLException ) if one of the commands sent to the database fails to execute properly or attempts to return a result set. |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
ResultSet executeQuery (String sql)
执行给定的SQL语句,该语句返回一个 ResultSet
对象。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : an SQL statement to be sent to the database, typically a static SQL SELECT statement |
Returns | |
---|---|
ResultSet |
a ResultSet object that contains the data produced by the given query; never null |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the given SQL statement produces anything other than a single ResultSet object, the method is called on a PreparedStatement or CallableStatement |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
int executeUpdate (String sql)
执行给定的SQL语句,这可能是 INSERT
, UPDATE
,或 DELETE
声明,或者不返回任何内容,如SQL DDL语句的SQL语句。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : an SQL Data Manipulation Language (DML) statement, such as INSERT , UPDATE or DELETE ; or an SQL statement that returns nothing, such as a DDL statement. |
Returns | |
---|---|
int |
either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the given SQL statement produces a ResultSet object, the method is called on a PreparedStatement or CallableStatement |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
int executeUpdate (String sql, String[] columnNames)
执行给定的SQL语句并向驱动程序发出指示给定数组中指示的自动生成的键应该可用于检索的信号。 此数组包含目标表中包含应该使其可用的自动生成的键的列的名称。 如果SQL语句不是INSERT
语句,或者SQL语句能够返回自动生成的键(这些语句的列表是特定于供应商的),驱动程序将忽略该数组。
注意:不能在 PreparedStatement
或 CallableStatement
上调用此方法。
Parameters | |
---|---|
sql |
String : an SQL Data Manipulation Language (DML) statement, such as INSERT , UPDATE or DELETE ; or an SQL statement that returns nothing, such as a DDL statement. |
columnNames |
String : an array of the names of the columns that should be returned from the inserted row |
Returns | |
---|---|
int |
either the row count for INSERT , UPDATE , or DELETE statements, or 0 for SQL statements that return nothing |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the SQL statement returns a ResultSet object, the second argument supplied to this method is not a String array whose elements are valid column names, the method is called on a PreparedStatement or CallableStatement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
int executeUpdate (String sql, int[] columnIndexes)
执行给定的SQL语句并向驱动程序发出指示给定数组中指示的自动生成的键应该可用于检索的信号。 此数组包含目标表中包含应该使其可用的自动生成的键的列索引。 如果SQL语句不是INSERT
语句,或者SQL语句能够返回自动生成的键(这些语句的列表是特定于供应商的),驱动程序将忽略该数组。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : an SQL Data Manipulation Language (DML) statement, such as INSERT , UPDATE or DELETE ; or an SQL statement that returns nothing, such as a DDL statement. |
columnIndexes |
int : an array of column indexes indicating the columns that should be returned from the inserted row |
Returns | |
---|---|
int |
either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the SQL statement returns a ResultSet object,the second argument supplied to this method is not an int array whose elements are valid column indexes, the method is called on a PreparedStatement or CallableStatement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
int executeUpdate (String sql, int autoGeneratedKeys)
执行给定的SQL语句并用给定的标志向驱动程序发出有关是否应该使该Statement
对象产生的自动生成的密钥可用于检索的信号。 如果SQL语句不是INSERT
语句,或者SQL语句能够返回自动生成的键(这些语句的列表是特定于供应商的),驱动程序将忽略此标志。
注意:此方法无法在 PreparedStatement
或 CallableStatement
。
Parameters | |
---|---|
sql |
String : an SQL Data Manipulation Language (DML) statement, such as INSERT , UPDATE or DELETE ; or an SQL statement that returns nothing, such as a DDL statement. |
autoGeneratedKeys |
int : a flag indicating whether auto-generated keys should be made available for retrieval; one of the following constants: Statement.RETURN_GENERATED_KEYS Statement.NO_GENERATED_KEYS |
Returns | |
---|---|
int |
either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement , the given SQL statement returns a ResultSet object, the given constant is not one of those allowed, the method is called on a PreparedStatement or CallableStatement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method with a constant of Statement.RETURN_GENERATED_KEYS |
SQLTimeoutException |
when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement |
Connection getConnection ()
检索 Connection
生成此对象 Statement
对象。
Returns | |
---|---|
Connection |
the connection that produced this statement |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
int getFetchDirection ()
检索从数据库表中提取行的方向,这是从此Statement
对象生成的结果集的默认值。 如果此Statement
对象没有通过调用方法setFetchDirection
设置获取方向,则返回值是特定于实现的。
Returns | |
---|---|
int |
the default fetch direction for result sets generated from this Statement object |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
也可以看看:
int getFetchSize ()
检索结果集合的行数是默认为获取大小ResultSet
从该生成的对象Statement
对象。 如果此Statement
对象没有通过调用方法setFetchSize
设置获取大小,则返回值是特定于实现的。
Returns | |
---|---|
int |
the default fetch size for result sets generated from this Statement object |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
也可以看看:
ResultSet getGeneratedKeys ()
检索由于执行此Statement
对象而创建的所有自动生成的密钥。 如果这个Statement
对象没有生成任何键,则返回一个空的ResultSet
对象。
注意:如果未指定代表自动生成密钥的列,则JDBC驱动程序实现将确定最能代表自动生成密钥的列。
Returns | |
---|---|
ResultSet |
a ResultSet object containing the auto-generated key(s) generated by the execution of this Statement object |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
int getMaxFieldSize ()
检索由此ResultSet
对象生成的Statement
对象中可以返回字符和二进制列值的最大字节数。 此限制仅适用于BINARY
, VARBINARY
, LONGVARBINARY
, CHAR
, VARCHAR
, NCHAR
, NVARCHAR
, LONGNVARCHAR
个LONGVARCHAR
列。 如果超出限制,则会过多丢弃超量数据。
Returns | |
---|---|
int |
the current column size limit for columns storing character and binary values; zero means there is no limit |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
也可以看看:
int getMaxRows ()
检索ResultSet
对象生成的Statement
对象可以包含的最大行数。 如果超出此限制,多余的行将被无声地丢弃。
Returns | |
---|---|
int |
the current maximum number of rows for a ResultSet object produced by this Statement object; zero means there is no limit |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
也可以看看:
boolean getMoreResults (int current)
移动到此 Statement
对象的下一个结果,与任何电流 ResultSet
根据由给定的标志指定的指令对象(一个或多个),并且返回 true
如果下一个结果是 ResultSet
对象。
当以下情况属实时,没有更多结果:
// stmt is a Statement object ((stmt.getMoreResults(current) == false) && (stmt.getUpdateCount() == -1))
Parameters | |
---|---|
current |
int : one of the following Statement constants indicating what should happen to current ResultSet objects obtained using the method getResultSet : Statement.CLOSE_CURRENT_RESULT , Statement.KEEP_CURRENT_RESULT , or Statement.CLOSE_ALL_RESULTS |
Returns | |
---|---|
boolean |
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, this method is called on a closed Statement or the argument supplied is not one of the following: Statement.CLOSE_CURRENT_RESULT , Statement.KEEP_CURRENT_RESULT or Statement.CLOSE_ALL_RESULTS |
SQLFeatureNotSupportedException |
if DatabaseMetaData.supportsMultipleOpenResults returns false and either Statement.KEEP_CURRENT_RESULT or Statement.CLOSE_ALL_RESULTS are supplied as the argument. |
也可以看看:
boolean getMoreResults ()
移动到 Statement
对象的下一个结果,如果它是 ResultSet
对象,则返回 true
,并隐式关闭使用方法 getResultSet
获取的所有当前 ResultSet
对象。
当以下情况属实时,没有更多结果:
// stmt is a Statement object ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))
Returns | |
---|---|
boolean |
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 or this method is called on a closed Statement |
也可以看看:
int getQueryTimeout ()
检索驱动程序将等待Statement
对象执行的Statement
。 如果超出限制,则引发SQLException
。
Returns | |
---|---|
int |
the current query timeout limit in seconds; zero means there is no limit |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
也可以看看:
ResultSet getResultSet ()
以ResultSet
对象的形式检索当前结果。 每个结果只能调用一次该方法。
Returns | |
---|---|
ResultSet |
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 or this method is called on a closed Statement |
也可以看看:
int getResultSetConcurrency ()
检索由此 ResultSet
对象生成的 Statement
对象的结果集并发性。
Returns | |
---|---|
int |
either ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
int getResultSetHoldability ()
检索由此 ResultSet
对象生成的 Statement
对象的结果集可保存性。
Returns | |
---|---|
int |
either ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
int getResultSetType ()
检索由此 ResultSet
对象生成的 Statement
对象的结果集类型。
Returns | |
---|---|
int |
one of ResultSet.TYPE_FORWARD_ONLY , ResultSet.TYPE_SCROLL_INSENSITIVE , or ResultSet.TYPE_SCROLL_SENSITIVE |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
int getUpdateCount ()
以更新计数检索当前结果; 如果结果是ResultSet
对象或没有更多结果,则返回-1。 每个结果只能调用一次该方法。
Returns | |
---|---|
int |
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 or this method is called on a closed Statement |
也可以看看:
SQLWarning getWarnings ()
检索此Statement
对象通过调用报告的第一个警告。 随后的Statement
对象警告将被链接到此SQLWarning
对象。
每次语句被重新执行时,警告链都会自动清除。 此方法不能在封闭的Statement
对象上调用; 这样做会导致SQLException
被抛出。
注意:如果您正在处理 ResultSet
对象,则与该 ResultSet
对象上的读取相关的任何警告都将链接在该对象上,而不是链接在产生该对象的 Statement
对象上。
Returns | |
---|---|
SQLWarning |
the first SQLWarning object or null if there are no warnings |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
boolean isClosed ()
检索此Statement
对象是否已关闭。 如果方法关闭已被调用,或者自动关闭,则关闭Statement
。
Returns | |
---|---|
boolean |
true if this Statement object is closed; false if it is still open |
Throws | |
---|---|
SQLException |
if a database access error occurs |
boolean isPoolable ()
返回一个值,指示 Statement
是否可以 Statement
。
Returns | |
---|---|
boolean |
true if the Statement is poolable; false otherwise |
Throws | |
---|---|
SQLException |
if this method is called on a closed Statement |
也可以看看:
void setCursorName (String name)
将SQL游标名称设置为给定的String
,随后的Statement
对象execute
方法将使用该名称。 然后可以在SQL定位的更新或删除语句中使用此名称来标识由此语句生成的ResultSet
对象中的当前行。 如果数据库不支持定位更新/删除,则此方法为noop。 为确保游标具有适当的隔离级别以支持更新,游标的SELECT
语句应具有格式SELECT FOR UPDATE
。 如果FOR UPDATE
不存在,定位更新可能会失败。
注意:根据定义,定位更新和删除的执行必须由与生成用于定位的ResultSet
对象不同的Statement
对象完成。 而且,游标名称在连接中必须是唯一的。
Parameters | |
---|---|
name |
String : the new cursor name, which must be unique within a connection |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
void setEscapeProcessing (boolean enable)
设置退出处理的开启或关闭。 如果转义扫描处于打开状态(默认状态),驱动程序会在将SQL语句发送到数据库之前执行转义替换。 注意:由于准备好的语句在进行此调用之前通常会被解析,因此禁用PreparedStatements
对象的转义处理将不起作用。
Parameters | |
---|---|
enable |
boolean : true to enable escape processing; false to disable it |
Throws | |
---|---|
SQLException |
if a database access error occurs or this method is called on a closed Statement |
void setFetchDirection (int direction)
为驱动程序提供有关使用此Statement
对象创建的对象在ResultSet
对象中的处理方向的提示。 默认值是ResultSet.FETCH_FORWARD
。
请注意,此方法设置由此Statement
对象生成的结果集的默认获取方向。 每个结果集都有自己的获取和设置自己获取方向的方法。
Parameters | |
---|---|
direction |
int : the initial direction for processing rows |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement or the given direction is not one of ResultSet.FETCH_FORWARD , ResultSet.FETCH_REVERSE , or ResultSet.FETCH_UNKNOWN |
也可以看看:
void setFetchSize (int rows)
当此Statement
ResultSet
对象需要更多行时,向JDBC驱动程序提示应该从数据库中提取的行Statement
。 如果指定的值为零,则提示将被忽略。 默认值为零。
Parameters | |
---|---|
rows |
int : the number of rows to fetch |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement or the condition rows >= 0 is not satisfied. |
也可以看看:
void setMaxFieldSize (int max)
设置此ResultSet
对象生成的Statement
对象中可以返回字符和二进制列值的最大字节数限制。 此限制仅适用于BINARY
, VARBINARY
, LONGVARBINARY
, CHAR
, VARCHAR
, NCHAR
, NVARCHAR
, LONGNVARCHAR
个LONGVARCHAR
领域。 如果超出限制,则会过多丢弃超量数据。 为了获得最大的便携性,请使用大于256的值。
Parameters | |
---|---|
max |
int : the new column size limit in bytes; zero means there is no limit |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement or the condition max >= 0 is not satisfied |
也可以看看:
void setMaxRows (int max)
设置由此ResultSet
对象生成的任何Statement
对象可包含的给定数量的最大行数限制。 如果超出限制,超出的行将被无声地丢弃。
Parameters | |
---|---|
max |
int : the new max rows limit; zero means there is no limit |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement or the condition max >= 0 is not satisfied |
也可以看看:
void setPoolable (boolean poolable)
要求将Statement
合并或不合并。 指定的值是语句池实现的一个提示,指示应用程序是否希望语句被合并。 由声明池管理员决定是否使用提示。
一个语句的极大值适用于驱动程序实现的内部语句高速缓存和应用程序服务器和其他应用程序实现的外部语句高速缓存。
默认情况下, Statement
在创建时 CallableStatement
被 PreparedStatement
, CallableStatement
和 CallableStatement
创建时可以 CallableStatement
。
Parameters | |
---|---|
poolable |
boolean : requests that the statement be pooled if true and that the statement not be pooled if false |
Throws | |
---|---|
SQLException |
if this method is called on a closed Statement |
void setQueryTimeout (int seconds)
将驱动程序等待Statement
对象执行的秒数设置为给定秒数。 默认情况下,对于运行语句完成所允许的时间量没有限制。 如果超出限制,则抛出SQLTimeoutException
。 JDBC驱动程序必须将此限制到execute
, executeQuery
和executeUpdate
方法。
注意: JDBC驱动程序实现也可能将此限制应用于 ResultSet
方法(有关详细信息,请参阅您的驱动程序供应商文档)。
注意:对于 Statement
批处理,它的实现定义为超时是应用于通过 addBatch
方法添加的单个SQL命令还是应用于由 executeBatch
方法调用的整批SQL命令(请参阅驱动程序供应商文档了解详情)。
Parameters | |
---|---|
seconds |
int : the new query timeout limit in seconds; zero means there is no limit |
Throws | |
---|---|
SQLException |
if a database access error occurs, this method is called on a closed Statement or the condition seconds >= 0 is not satisfied |
也可以看看: