When an SQL query executes, the results form a pseudo-table that contains all rows that fit the query criteria. For instance, here's a textual representation of the results of the query string
"SELECT EMP_CODE, EMP_NAME, EMP_ADDRESS FROM EMPLOYEE"
:EMP_CODE | EMP_NAME | EMP_ADDRESS |
---|---|---|
1 | AJAY | DELHI |
2 | VIJAY | NOIDA |
3 | SANJAY | LUCKNOW |
4 | RAMESH | KANPUR |
5 | PANKAJ | PUNE |
This kind of textual representation is not very useful for Java programs. Instead, JDBC uses the
java.sql.ResultSet
interface to encapsulate the query results as Java primitive types and objects. You can think of a ResultSet as an object that represents an underlying table of query results, where you use method calls to navigate between rows and retrieve particular column values.
Java program might handle the previous query as follows:
Syntax
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT EMP_CODE, EMP_NAME, EMP_ADDRESS FROM EMPLOYEE");
EmoticonEmoticon