Which method is used to execute a SQL SELECT query in JDBC?
Answer:
Explanation:
The executeQuery()
method in JDBC is used to execute SQL SELECT queries, which retrieve data from the database. This method returns a ResultSet
object, which represents the data returned by the query. The ResultSet
allows the application to iterate over the rows of data and extract the necessary information.
executeQuery()
is specifically designed for SELECT queries and is one of the most commonly used methods in JDBC. It is used when the query is expected to return a result set, such as retrieving records from a table. The method executes the query and processes the results in a manner that is both efficient and easy to use.
Understanding the proper use of executeQuery()
is fundamental for developers working with databases in Java. It is a key part of the process of retrieving and manipulating data, making it an essential tool in any JDBC-based application.