[英]Statement.execute(SQL) JDBC java
Since the following method returns a boolean, I would like to know how can I get a ResultSet
out of it if the method returns true
hence it is a ResultSet
execute由于以下方法返回一个布尔值,我想知道如果该方法返回
true
则如何从中获取ResultSet
,因此它是一个ResultSet
执行
boolean execute(String sql)
throws SQLException
When using execute
method, you can get the resultset(s)
by using : Statement.getResultSet
.使用
execute
方法时,您可以使用: Statement.getResultSet
获取resultset(s)
。 Here are the details from javadoc :以下是来自javadoc的详细信息:
execute : Returns true if the first object that the query returns is a ResultSet object.
execute :如果查询返回的第一个对象是 ResultSet 对象,则返回 true。 Use this method if the query could return one or more ResultSet objects.
如果查询可以返回一个或多个 ResultSet 对象,请使用此方法。 Retrieve the ResultSet objects returned from the query by repeatedly calling Statement.getResultSet.
通过重复调用 Statement.getResultSet 来检索从查询返回的 ResultSet 对象。
To execute a query, call an execute method from
Statement
such as the following:要执行查询,请从
Statement
调用 execute 方法,如下所示:
execute
: Returnstrue
if the first object that the query returns is aResultSet
object.execute
:如果查询返回的第一个对象是ResultSet
对象,则返回true
。 Use this method if the query could return one or moreResultSet
objects.如果查询可以返回一个或多个
ResultSet
对象,请使用此方法。 Retrieve theResultSet
objects returned from the query by repeatedly callingStatement.getResultSet
.通过重复调用
Statement.getResultSet
检索从查询返回的ResultSet
对象。executeQuery
: Returns oneResultSet
object.executeQuery
:返回一个ResultSet
对象。executeUpdate
: Returns an integer representing the number of rows affected by the SQL statement.executeUpdate
:返回一个整数,表示受 SQL 语句影响的行数。 Use this method if you are usingINSERT
,DELETE
, orUPDATE
SQL statements.如果您使用
INSERT
、DELETE
或UPDATE
SQL 语句,请使用此方法。
Trail: JDBC Database Access (The Java Tutorials) Trail:JDBC 数据库访问(Java 教程)
Read the javadoc.阅读 javadoc。
getResultSet()
getMoreResults()
Call getResultSet method of Statement
object if execute returns true.如果execute返回 true,则调用
Statement
对象的getResultSet方法。
Accroding to Statement#execute根据声明#execute
The execute method executes an SQL statement and indicates the form of the first result.
execute 方法执行一条 SQL 语句并指示第一个结果的形式。 You must then use the methods getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result(s).
然后您必须使用 getResultSet 或 getUpdateCount 方法检索结果,并使用 getMoreResults 移动到任何后续结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.