aaberg / sql2o

sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.
http://sql2o.org
MIT License
1.15k stars 229 forks source link

Row map does not support entrySet #221

Open atjiu opened 8 years ago

atjiu commented 8 years ago
        String sql = "SELECT * FROM blog";
        try(Connection con = MyDao.sql2o.open()) {
            List<Map<String, Object>> blogs = con.createQuery(sql)
                    .executeAndFetchTable()
                    .asList();
            return success(blogs);
        }

When I execute the code above, an exception is thrown Row map does not support entrySet

kkrgwbj commented 8 years ago
public Map<String, Object> asMap() {
        Map map = new HashMap();
        Set<String> keys = columnNameToIdxMap.keySet();
        Iterator iterator = keys.iterator();
        while (iterator.hasNext()) {
            String colum = iterator.next().toString();
            System.out.println(colum);
            int index = columnNameToIdxMap.get(colum);
            map.put(colum, values[index]);
        }
        return map;
    }
hellokaton commented 8 years ago
public Map<String, Object> asMap() {
    try {
        Set<String> columnNames = columnNameToIdxMap.keySet();
        Map<String, Object> map = new HashMap<String, Object>(columnNames.size());
        String[] keys = columnNames.toArray(new String[columnNames.size()]);
        for(int i=0, len=values.length; i<len; i++){
            String key = keys[i];
            Object value = getObject(key);
            map.put(key, value);
        }
        return map;
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}
kkrgwbj commented 8 years ago

@biezhi 你的这个有点复杂了。