Java Utililty Methods SQL ResultSet to

List of utility methods to do SQL ResultSet to

Description

The list of methods to do SQL ResultSet to are organized into topic(s).

Method

Objectconvert(int sqlType, String type, ResultSet rs, String name)
convert
switch (sqlType) {
case Types.ARRAY:
    return rs.getArray(name);
case Types.BIGINT:
    return rs.getLong(name);
case Types.BINARY:
case Types.LONGVARBINARY:
case Types.VARBINARY:
...
List>convert(ResultSet rs)
convert
ResultSetMetaData rsmd = rs.getMetaData();
List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
while (rs.next()) {
    int numColumns = rsmd.getColumnCount();
    Map<String, Object> obj = new HashMap<String, Object>();
    for (int i = 1; i < numColumns + 1; i++) {
        String column_name = rsmd.getColumnName(i).toLowerCase();
        if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
...
JSONArrayconvertResultSetToJSON(ResultSet resultSet)
Convert a result set into a JSON Array
JSONArray jsonArray = new JSONArray();
if (resultSet != null) {
    while (resultSet.next()) {
        int total_rows = resultSet.getMetaData().getColumnCount();
        JSONObject obj = new JSONObject();
        for (int i = 0; i < total_rows; i++) {
            int colNextIndex = i + 1;
            obj.put(resultSet.getMetaData().getColumnLabel(colNextIndex).toLowerCase(),
...
Collection>convertResultSetToMap(final ResultSet rs)
convert Result Set To Map
try {
    ResultSetMetaData metaData = rs.getMetaData();
    int colum = metaData.getColumnCount();
    Collection<Map<String, Object>> collection = new ArrayList<Map<String, Object>>();
    Map<String, Object> row = null;
    while (rs.next()) {
        row = new HashMap<String, Object>();
        for (int i = 0; i < colum; i++)
...
MapconvertToMap(Map metaData, ResultSet rs)
convert To Map
fillRowNames(metaData, rs);
Map<String, Object> row = new HashMap<String, Object>();
for (Map.Entry<String, Integer> entry : metaData.entrySet()) {
    Object value = null;
    if (Types.DATE == entry.getValue()) {
        value = formartDate(rs.getDate(entry.getKey()));
    } else if (Types.TIMESTAMP == entry.getValue()) {
        value = formartDateTime(rs.getTimestamp(entry.getKey()));
...
List>resultSet2List(ResultSet rs)
result Set List
List<Map<String, Object>> list = null;
if (rs != null) {
    list = new ArrayList<Map<String, Object>>();
    try {
        while (rs.next()) {
            Map<String, Object> map = resultSet2Map(rs);
            if (map != null && map.size() > 0) {
                list.add(map);
...
MapresultSet2Map(ResultSet rs)
result Set Map
Map<String, Object> map = null;
if (rs != null) {
    map = new HashMap<String, Object>();
    try {
        ResultSetMetaData rsMetaData = rs.getMetaData();
        int columnCount = rsMetaData.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            String cName = rsMetaData.getColumnLabel(i);
...
StringresultSetAsCSV(ResultSet rsh)
Return a resultset as a csv formatted string with control chars removed.
StringBuilder sb = new StringBuilder();
ResultSetMetaData rsmd = rsh.getMetaData();
int numColumns = rsmd.getColumnCount();
String colName1 = rsmd.getColumnName(1).replace("\"", "").replace(",", "").trim();
colName1 = colName1.substring(0, 1).toUpperCase() + ((colName1.length() > 0) ? colName1.substring(1) : "");
String colNames = "\"" + colName1 + "\"";
for (int i = 2; i < numColumns + 1; i++) {
    String colName = rsmd.getColumnName(i).replace("\"", "").replace(",", "").trim();
...
StringresultSetCurrentData(ResultSet rs)
result Set Current Data
ResultSetMetaData metaData = rs.getMetaData();
StringBuilder column = new StringBuilder();
int columns = metaData.getColumnCount();
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= columns; i++) {
    column.setLength(0);
    if (i > 1) {
        sb.append(" | ");
...
ObjectresultSetParseVO(ResultSet rs, Class cls)
result Set Parse VO
Object obj = cls.newInstance();
Field[] fs = cls.getDeclaredFields();
for (Field field : fs) {
    String name = field.getName();
    String value = rs.getString(rs.findColumn(name));
    field.set(obj, value);
return obj;
...