Statement objects use the executeQuery method to query the database. The method uses an SQL statement as input and returns a ResultSet object.
Note
- The method for executing a Statement object depends on the type of the SQL statement to be executed. If the Statement object indicates an SQL query that requires a ResultSet object be returned, the
executeQuerymethod 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 ResultSet object is returned for the SQL string being executed, the
executeQuerymethod does not throw an SQL exception.
Example: Use the Statement object st to run a query and return a ResultSet object that contains content of the name column in the customers table.
ResultSet rs = st.executeQuery ("SELECT name FROM customers");