Java examples for java.sql:ResultSet
result Set To List
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.sql.DataSource; import org.apache.log4j.Logger; public class Main{ /*w ww .j a v a 2 s . c o m*/ private static List resultSetToList(ResultSet rs) throws SQLException { List result = new ArrayList(); ResultSetMetaData metaData = rs.getMetaData(); int count = metaData.getColumnCount(); while (rs.next()) { Map resultMap = new HashMap(); for (int i = 0; i < count; i++) { String columnName = metaData.getColumnName(i + 1); resultMap.put(columnName, rs.getObject(i + 1)); } result.add(resultMap); } return result; } }