protected List<Map<String, Object>> query(String sql) throws SQLException { List<Map<String, Object>> hash = new ArrayList<Map<String, Object>>(); Statement stm = (Statement) con.createStatement(); ResultSet rs = stm.executeQuery(sql); ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData(); int j = md.getColumnCount(); while (rs.next()) { Map<String, Object> hs = new HashMap<String, Object>(); for (int i = 0; i < j; i++) { hs.put(md.getCatalogName(i), rs.getObject(i)); } hash.add(hs); } return hash; }
參考資料:http://blog.csdn.net/duanyipeng/article/details/7851138java
http://hi.baidu.com/chuansl/item/fe2484e6e9746da7c10d751csql