Java SQL ResultSet to resultSet2Map(ResultSet rs)

Here you can find the source of resultSet2Map(ResultSet rs)

Description

result Set Map

License

Open Source License

Declaration

private static Map<String, Object> resultSet2Map(ResultSet rs) 

Method Source Code

//package com.java2s;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import java.util.HashMap;

import java.util.Map;
import com.google.common.base.Strings;

public class Main {
    private static Map<String, Object> resultSet2Map(ResultSet rs) {
        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);
                    if (!Strings.isNullOrEmpty(cName)) {
                        map.put(cName, rs.getString(cName));
                    }//from   w  ww.  j a  v a2  s. c o m
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}

Related

  1. convert(ResultSet rs)
  2. convertResultSetToJSON(ResultSet resultSet)
  3. convertResultSetToMap(final ResultSet rs)
  4. convertToMap(Map metaData, ResultSet rs)
  5. resultSet2List(ResultSet rs)
  6. resultSetAsCSV(ResultSet rsh)
  7. resultSetCurrentData(ResultSet rs)
  8. resultSetParseVO(ResultSet rs, Class cls)
  9. resultSetToArrayList(ResultSet rs)