01: package org.claros.commons.db.handler;
02:
03: import java.sql.ResultSet;
04: import java.sql.ResultSetMetaData;
05: import java.sql.SQLException;
06: import java.util.HashMap;
07:
08: import org.apache.commons.dbutils.ResultSetHandler;
09:
10: /**
11: * @author Umut Gokbayrak
12: *
13: */
14: public class ItemResultSetHandler implements ResultSetHandler {
15:
16: /* (non-Javadoc)
17: * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
18: */
19: public Object handle(ResultSet rs) throws SQLException {
20: String name = null;
21: Object value = null;
22: ResultSetMetaData meta = rs.getMetaData();
23: int cols = meta.getColumnCount();
24: if (cols == 0) {
25: return null;
26: }
27: HashMap map = new HashMap(cols);
28:
29: for (int i = 0; i < cols; i++) {
30: name = meta.getColumnName(i + 1);
31: value = rs.getObject(i + 1);
32: map.put(name, value);
33: }
34: return map;
35: }
36: }
|