- Java BeanUtils Tutorial
- Java BeanUtils - Home
- Java BeanUtils - Overview
- Standard JavaBeans
- Background
- Basic Property Access
- Nested Property Access
- Customizing Introspection
- Suppressing Properties
- Dynamic Beans (DynaBeans)
- Background
- Basic DynaBeans
- ResultSetDynaClass
- RowSetDynaClass
- WrapDynaBean
- Lazy DynaBeans
- Data Type Conversions
- Background
- BeanUtils and ConvertUtils
- Create Custom Converters
- Locale Aware Conversions
- Utility Objects & Classes
- Utility Objects & Classes
Java BeanUtils - ResultSetDynaClass
Description
The ResultSet can be wrapped in the DynaBeans by using the ResultSetDynaClass which renders the results of SQL query as series of DynaBeans. The most commonly used collection is java.sql.ResultSet which is returned when JDBC driver uses SQL SELECT statement. The each row of result set can be made visible by using the Commons BeanUtils package.
You can make use of the ResultSetDynaClass by using the DynaBean interface as shown in the below code snippet:
Connection conn = ...; Statement stmt = conn.createStatement(); ResultSet res_set = stmt.executeQuery("select first_name, last_name from student"); Iterator rows = (new ResultSetDynaClass(res_set)).iterator(); while (rows.hasNext()) { DynaBean row = (DynaBean) rows.next(); System.out.println("First Name is:" + row.get("first_name") + " and Last Name is:" + row.get("last_name")); } rs.close(); stmt.close();
Advertisements
To Continue Learning Please Login
Login with Google