java用map集合装从数据库返回结果,具体代码如下:
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class MapRowMapper implements RowMapper<Map<String,Object>> {
@Override
public Map<String, Object> mapRow(ResultSet rs) throws SQLException {
Map<String, Object> map = new HashMap<String, Object>();
ResultSetMetaData rsmd = rs.getMetaData();
for(int i = 1;i <= rsmd.getColumnCount();i++) {
String columnName = rsmd.getColumnLabel(i);
Object columnValue = rs.getObject(columnName);
map.put(columnName, columnValue);
}
return map;
}
}
更多信息请查看IT技术专栏