Run queries and retrieve ResultSet objects

2023-07-26 09:37:05  Updated

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 executeQuery method is applicable. If the SQL statement is a DDL or DML statement for updating the count, the executeUpdate method is applicable. If the type of the SQL statement is unknown, the execute method is applicable.
  • For OceanBase Connector/J, even if no ResultSet object is returned for the SQL string being executed, the executeQuery method 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");

Contact Us