算是不常用的东西,java中的ResultSet转List
import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class ListResult { private List<Map<String, Object>> dbRestlt; public ListResult(ResultSet rs) { setDBRestlt(rs); } private void setDBRestlt(ResultSet rs) { try { if (rs == null) { return; } ResultSetMetaData md = rs.getMetaData(); int num = md.getColumnCount(); dbRestlt = new ArrayList<>(); while (rs.next()) { Map<String, Object> mapOfColValues = new HashMap<>(num); for (int i = 1; i <= num; i++) { mapOfColValues.put(md.getColumnName(i), rs.getObject(i)); } dbRestlt.add(mapOfColValues); } rs.close(); } catch (SQLException e) { e.printStackTrace(); } } public List<Map<String, Object>> getListRestlt() { return dbRestlt; } }