The Statement object uses the executeQuery method to query the database. The method uses an SQL statement as input and returns a JDBC ResultSet object. Note
The method for executing the
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 a standard JDBC driver, if no
ResultSetobject is returned for the SQL string being executed, theexecuteQuerymethod throws an SQL exception. For the OceanBaseJDBC driver (OceanBase Client), even if noResultSetobject is returned for the SQL string being executed, theexecuteQuerymethod does not throw an SQL exception.
Example: Using 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");