Sunday 9 June 2013

JDBC ResultSet

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_CODEEMP_NAMEEMP_ADDRESS
1AJAYDELHI
2VIJAYNOIDA
3SANJAYLUCKNOW
4RAMESHKANPUR
5PANKAJPUNE
This kind of textual representation is not very useful for Java programs. Instead, JDBC uses thejava.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