Statement objects use the executeQuery method to query the database. The method takes an SQL statement as input and returns a ResultSet object.
Note
- The method for executing a
Statementobject depends on the type of the SQL statement to be executed. If theStatementobject indicates an SQL query that requires aResultSetobject be returned, theexecuteQuerymethod is applicable. If the SQL statement is a DDL or DML statement for updating the count, theexecuteUpdatemethod is applicable. If the type of the SQL statement is unknown, theexecutemethod is applicable. - For OceanBase Connector/J, even if no
ResultSetobject is returned for the SQL string being executed, theexecuteQuerymethod does not throw an SQL exception.
Example: Use the Statement object st to run a query and return a ResultSet object that contains data of the name column in the customers table.
ResultSet rs = st.executeQuery ("SELECT name FROM customers");