Rollerball
Rollerball

Reputation: 13108

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

boolean execute(String sql)
            throws SQLException

Upvotes: 0

Views: 1605

Answers (4)

Juned Ahsan
Juned Ahsan

Reputation: 68715

When using execute method, you can get the resultset(s) by using : Statement.getResultSet. Here are the details from javadoc:

execute: Returns true if the first object that the query returns is a ResultSet object. Use this method if the query could return one or more ResultSet objects. Retrieve the ResultSet objects returned from the query by repeatedly calling Statement.getResultSet.

Upvotes: 2

Paul Vargas
Paul Vargas

Reputation: 42020

To execute a query, call an execute method from Statement such as the following:

  • execute: Returns true if the first object that the query returns is a ResultSet object. Use this method if the query could return one or more ResultSet objects. Retrieve the ResultSet objects returned from the query by repeatedly calling Statement.getResultSet.
  • executeQuery: Returns one ResultSet object.
  • executeUpdate: Returns an integer representing the number of rows affected by the SQL statement. Use this method if you are using INSERT, DELETE, or UPDATE SQL statements.

Trail: JDBC Database Access (The Java Tutorials)

Upvotes: 2

Prabhaker A
Prabhaker A

Reputation: 8473

Call getResultSet method of Statement object if execute returns true.
Accroding to Statement#execute

The execute method executes an SQL statement and indicates the form of the first result. You must then use the methods getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result(s).

Upvotes: 1

Eric Stein
Eric Stein

Reputation: 13672

Read the javadoc.

getResultSet()
getMoreResults()

Upvotes: 1

Related Questions