java用map集合裝從數(shù)據(jù)庫返回結(jié)果,具體代碼如下:
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技術(shù)專欄