List of utility methods to do SQL ResultSet Read
List | getHashMap(ResultSet resultSet) Description - static method which takes the result set as an argument ,iterates over it to build a list of maps with column name as key,column value as its value List<Map<String, Object>> rowList = new ArrayList<>(); ResultSetMetaData metaData = resultSet.getMetaData(); int colCount = metaData.getColumnCount(); while (resultSet.next()) { Map<String, Object> columns = new HashMap<>(); for (int i = 1; i <= colCount; i++) { columns.put(metaData.getColumnLabel(i), resultSet.getObject(i)); rowList.add(columns); return rowList; |
List | getHeaders(ResultSetMetaData rsmd) get Headers List<String> h = new ArrayList<String>(); int columns = rsmd.getColumnCount(); for (int i = 1; i <= columns; i++) { h.add(rsmd.getColumnName(i)); return h; |
String | getHighPrecisionString(ResultSet rs, int ix, int sql_type) get High Precision String switch (sql_type) { case Types.DATE: return getString(rs, ix, Types.TIMESTAMP); default: return getString(rs, ix, sql_type); |
String | getHtmlRows(ResultSet results) get Html Rows StringBuffer htmlRows = new StringBuffer(); ResultSetMetaData metaData = results.getMetaData(); int columnCount = metaData.getColumnCount(); htmlRows.append("<tr>"); for (int i = 1; i <= columnCount; i++) htmlRows.append("<td><b>" + metaData.getColumnName(i) + "</td>"); htmlRows.append("</tr>"); while (results.next()) { ... |
String | getHtmlTable(ResultSet results) get Html Table StringBuilder htmlTable = new StringBuilder(); ResultSetMetaData metaData = results.getMetaData(); int columnCount = metaData.getColumnCount(); htmlTable.append("<table>"); htmlTable.append("<tr>"); for (int i = 1; i <= columnCount; i++) { htmlTable.append("<th>"); htmlTable.append(metaData.getColumnName(i)); ... |
Long | getId(ResultSet key) Extract key from given ResultSet. if (key.getMetaData().getColumnCount() != 1) { throw new IllegalArgumentException("Given ResultSet contains more columns"); if (key.next()) { Long result = key.getLong(1); if (key.next()) { throw new IllegalArgumentException("Given ResultSet contains more rows"); return result; } else { throw new IllegalArgumentException("Given ResultSet contain no rows"); |
int | getIndex(ResultSet rs, int index) get Index return rs.getInt(index);
|
List | getList(ResultSet resultSet, String columnLabel, Class get List return Arrays.asList(getArray(resultSet, columnLabel, clazz));
|
List | getList(ResultSet rs) get List if (rs == null) { return null; ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>(50); while (rs.next()) { HashMap<String, String> row = new HashMap<String, String>(columns); ... |
List | getListFromRS(Class get List From RS return getListFromRS(clazz, rs, false);
|