public String viewUserNames() { return jdbcTemplate .query( "select loginid from USERLOGIN where logintype='user' or logintype='owner' order by userid", new ResultSetExtractor<String>() { String s = ""; public String extractData(ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { s = s + rs.getString(1) + ","; } return s; } }); }
/** * 取分页 * * @param jt * jdbcTemplate * @param sqlFetchRows * 查询数据的sql * @param args * 查询参数 * @param size * 大小 * @param rowMapper * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public List<E> fetchList(final JdbcTemplate jt, final String sqlFetchRows, final Object args[], final int size, final ParameterizedRowMapper<E> rowMapper) { if (size == 0) { return null; } final Page<E> page = new Page<E>(); // TODO 在数据量很大时, limit效率很低 final String selectSQL = sqlFetchRows + " limit " + size; jt.query(selectSQL, args, new ResultSetExtractor() { public Object extractData(ResultSet rs) throws SQLException, DataAccessException { final List<E> pageItems = page.getPageItems(); int currentRow = 0; while (rs.next()) { pageItems.add(rowMapper.mapRow(rs, currentRow++)); } return pageItems; } }); return page.getPageItems(); }
@Test public void testResultSetExtractorPrototypeInstantiation() { Set<String> tableAliases = new HashSet<>(); tableAliases.add("wayseg"); tableAliases.add("xit"); ResultSetExtractor<? extends IBaseSegment> rsExtractor1 = resultSetExtractorFactory.getResultSetExtractor(tableAliases); ResultSetExtractor<? extends IBaseSegment> rsExtractor2 = resultSetExtractorFactory.getResultSetExtractor(tableAliases); try { rsExtractor1.extractData(null); rsExtractor2.extractData(null); } catch (DataAccessException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Assert.assertNotEquals(rsExtractor1, rsExtractor2); }
private Object executeSingleResultQuery(String query, Map<?, ?> params) { return jdbcTemplate.query(query, params, new ResultSetExtractor() { @Override public Object extractData(ResultSet rs) throws SQLException, DataAccessException { Object data = null; if( rs.next() ) { data = rs.getObject(1); // Sanity check - ensure only a single result if( rs.next() ) { throw new IncorrectResultSizeDataAccessException(1); } } return data; } }); }
public String viewFileName() { return jdbcTemplate.query( "select * from CLOUDFILEDATA order by FILEDATAID", new ResultSetExtractor<String>() { String s = ""; public String extractData(ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { s = s + rs.getString(5) + ","; } return s; } }); }
public String viewFileName(int userid) { return jdbcTemplate .query( "select * from CLOUDFILEDATA where groupname=(select (select groupname from groups where groupid=groupusers.groupid) from groupusers where userid=" + userid + ") order by FILEDATAID", new ResultSetExtractor<String>() { String s = ""; public String extractData(ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { s = s + rs.getString(5) + ","; } return s; } }); }
public String viewFileKey(String filename) { return jdbcTemplate.query( "select PUBLICKEY from CLOUDFILEDATA where filename='" + filename.trim() + "'", new ResultSetExtractor<String>() { String s = ""; public String extractData(ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { s = s + rs.getString(1) + ","; } return s; } }); }
public String viewFileSignature(String groupname) { return jdbcTemplate.query( "select GROUPSIGNATURE from GROUPS where GROUPNAME='" + groupname.trim() + "'", new ResultSetExtractor<String>() { String s = ""; public String extractData(ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { s = s + rs.getString(1) + ","; } return s; } }); }
public Users viewGroupname(final Users users) { return jdbcTemplate .query( "select userid,(select (select groupname from groups where groupid=GROUPUSERS.groupid) from GROUPUSERS where userid=userlogin.userid) from userlogin where loginid='" + users.getLoginid() + "'", new ResultSetExtractor<Users>() { public Users extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { users.setGroupname(rs.getString(2)); users.setUserid(rs.getInt(1)); } return users; } }); }
public Users managerLoginCheck(Users users) { return jdbcTemplate.query("select * from userlogin where loginid='" + users.getLoginid() + "' and password='" + users.getPassword() + "' and logintype='manager'", new ResultSetExtractor<Users>() { public Users extractData(ResultSet rs) throws SQLException, DataAccessException { Users user = new Users(); if (rs.next()) { user.setUserid(rs.getInt(1)); user.setLoginid(rs.getString(2)); user.setLogintype(rs.getString(3)); } return user; } }); }
public Object[] viewUserLoginMetaData() { return jdbcTemplate.query("select * from userlogin", new ResultSetExtractor<Object[]>() { public Object[] extractData(ResultSet rs) throws SQLException, DataAccessException { ResultSetMetaData resultSetMetaData = rs.getMetaData(); String tablemetadata[] = new String[] { resultSetMetaData.getColumnName(1), resultSetMetaData.getColumnName(2), resultSetMetaData.getColumnName(4), resultSetMetaData.getColumnName(5), resultSetMetaData.getColumnName(6), "GroupName", }; return tablemetadata; } }); }
public Object[] viewCloudMetaData() { return jdbcTemplate.query( "select * from CLOUDFILEDATA order by FILEDATAID", new ResultSetExtractor<Object[]>() { public Object[] extractData(ResultSet rs) throws SQLException, DataAccessException { ResultSetMetaData resultSetMetaData = rs.getMetaData(); String tablemetadata[] = new String[] { resultSetMetaData.getColumnName(1), resultSetMetaData.getColumnName(2), resultSetMetaData.getColumnName(3), resultSetMetaData.getColumnName(4), resultSetMetaData.getColumnName(5), resultSetMetaData.getColumnName(6), resultSetMetaData.getColumnName(9), resultSetMetaData.getColumnName(10), resultSetMetaData.getColumnName(11), }; return tablemetadata; } }); }
public Boolean viewGroupMembers() { return jdbcTemplate.query("select * from groups", new ResultSetExtractor<Boolean>() { public Boolean extractData(ResultSet rs) throws SQLException, DataAccessException { boolean b = new File(new File(".").getAbsolutePath() + "\\" + "groups").mkdir(); while (rs.next()) { boolean path = new File(new File("groups") .getAbsolutePath() + "\\" + rs.getString(2)).mkdir(); try { createUserFloders(rs.getInt(1), new File( "groups\\" + rs.getString(2)) .getAbsolutePath()); } catch (Exception e) { // TODO: handle exception } } return true; } }); }
public Boolean usergroupcount(final Users users) { String countuserssql = "select GROUPMEMBERCOUNT from GROUPS where GROUPNAME='" + users.getNewgroupname() + "'"; final Boolean usercount = jdbcTemplate.query(countuserssql, new ResultSetExtractor<Boolean>() { boolean s; public Boolean extractData(ResultSet rs) throws SQLException, DataAccessException { int i = 0; if (rs.next()) { System.out.println(rs.getInt(1)); try { s = userChangeGroup(rs.getInt(1), viewGroupname(users)); } catch (Exception e) { System.out.println(e); } } return s; } }); return usercount; }
public Integer groupMemberCount(String groupname) { String countuserssql = "select GROUPMEMBERCOUNT from GROUPS where GROUPNAME='" + groupname + "'"; final Integer usercount = jdbcTemplate.query(countuserssql, new ResultSetExtractor<Integer>() { int i = 0; public Integer extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { i = rs.getInt(1); } return i; } }); return usercount; }
@Override public List<Book> findAllBooks(String author) { // TODO Auto-generated method stub System.out.println(author); String FIND_ALL_Author="select * from book where author=?"; return jdbcTemplate.query(FIND_ALL_Author,new String[]{author}, new ResultSetExtractor<List<Book>>() { List<Book>books=new ArrayList(); @Override public List<Book> extractData(ResultSet set) throws SQLException, DataAccessException { // TODO Auto-generated method stub while(set.next()) { Book book=new Book(); book.setAuthor(set.getString("author")); book.setBookName(set.getString("bookName")); book.setISBN(set.getLong("ISBN")); book.setPublication(set.getString("publication")); book.setDescription(set.getString("description")); books.add(book); } return books; } }); }
@Override public List<Book> findAllBooks(String author) { // TODO Auto-generated method stub System.out.println(author); String FIND_ALL_Author = "select * from book where author=?"; return jdbcTemplate.query(FIND_ALL_Author, new String[] { author }, new ResultSetExtractor<List<Book>>() { List<Book> books = new ArrayList(); @Override public List<Book> extractData(ResultSet set) throws SQLException, DataAccessException { // TODO Auto-generated method stub while (set.next()) { Book book = new Book(); book.setAuthor(set.getString("author")); book.setBookName(set.getString("bookName")); book.setISBN(set.getLong("ISBN")); book.setPublication(set.getString("publication")); book.setDescription(set.getString("description")); books.add(book); } return books; } }); }
private List<FieldSchema> getPartitionKeys(final String databaseName, final String tableName, final boolean forceDisableAudit) { final List<FieldSchema> result = Lists.newArrayList(); final ResultSetExtractor<List<FieldSchema>> handler = rs -> { while (rs.next()) { final String name = rs.getString("pkey_name"); final String type = rs.getString("pkey_type"); result.add(new FieldSchema(name, type, null)); } return result; }; final Optional<QualifiedName> sourceTable = getSourceTableName(databaseName, tableName, forceDisableAudit); return sourceTable.map(qualifiedName -> jdbcTemplate .query(SQL.SQL_GET_AUDIT_TABLE_PARTITION_KEYS, new Object[]{databaseName, tableName, qualifiedName.getDatabaseName(), qualifiedName.getTableName()}, new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}, handler)) .orElseGet(() -> jdbcTemplate .query(SQL.SQL_GET_PARTITION_KEYS, new Object[]{databaseName, tableName}, new int[]{Types.VARCHAR, Types.VARCHAR}, handler)); }
private Map<Long, Map<String, String>> getParameters(final List<Long> ids, final String sql, final String idName) { // Create the sql final StringBuilder queryBuilder = new StringBuilder(sql); if (!ids.isEmpty()) { queryBuilder.append(" and ").append(idName) .append(" in ('").append(Joiner.on("','").skipNulls().join(ids)).append("')"); } final ResultSetExtractor<Map<Long, Map<String, String>>> handler = rs -> { final Map<Long, Map<String, String>> result = Maps.newHashMap(); while (rs.next()) { final Long id = rs.getLong(idName); final String key = rs.getString("param_key"); final String value = rs.getString("param_value"); final Map<String, String> parameters = result.computeIfAbsent(id, k -> Maps.newHashMap()); parameters.put(key, value); } return result; }; return jdbcTemplate.query(queryBuilder.toString(), handler); }
/** * 첫번쨰로우의 첫번쨰 컬럼값 리턴. <br/> * 값이 없는경우 NULL <br/> * * @작성자 : KYJ * @작성일 : 2017. 11. 27. * @param dataSource * @param sql * @param paramMap * @return */ public static String selectScala(DataSource dataSource, final String sql, MapSqlParameterSource paramMap) { String r = null; try { noticeQuery(sql); NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); ResultSetExtractor<String> extr = new ResultSetExtractor<String>() { @Override public String extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { return rs.getString(1); } return null; } }; r = jdbcTemplate.query(sql, paramMap, extr); } catch (Exception e) { throw e; } finally { cleanDataSource(); } return r; }
@Override public byte[] read(String filename) throws IOException { String sql = "select data from " + TABLE + " where filename='" + filename + "';"; byte[] data = this.jdbc.getJdbcTemplate().query(sql, new ResultSetExtractor<byte[]>() { @Override public byte[] extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.first()) { return rs.getBytes(1); } else { return null; } } }); if (data == null) { throw new FileNotFoundException(filename); } return data; }
public boolean translator(DataSource sourceDs, Record record) { ColumnValue idColum = record.getColumnByName("id"); if (idColum != null) { // 需要根据test.id字段,和另一张表做join,提取到关联id记录的name字段,合并输出到一个目标表 JdbcTemplate jdbcTemplate = new JdbcTemplate(sourceDs); String name_value = (String) jdbcTemplate.query("select NAME FROM JOIN_NAME WHERE JOIN_ID = " + idColum.getValue().toString(), new ResultSetExtractor() { public Object extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { return rs.getString("NAME"); } return null; } }); ColumnMeta nameMeta = new ColumnMeta("name", Types.VARCHAR); ColumnValue nameColumn = new ColumnValue(nameMeta, name_value); record.addColumn(nameColumn); } return super.translator(record); }
public ResultSetExtractor getSkeletonExtractor(Class<? extends Skeleton> c) { if (c.equals(ObservationSkeleton.class)) { return new ObservationSkeletonExtractor(); } if (c.equals(ObservationMetaReadAccessSkeleton.class)) { return new ReadAccessSkeletonExtractor(ObservationMetaReadAccessSkeleton.class); } if (c.equals(PlaneMetaReadAccessSkeleton.class)) { return new ReadAccessSkeletonExtractor(PlaneMetaReadAccessSkeleton.class); } if (c.equals(PlaneDataReadAccessSkeleton.class)) { return new ReadAccessSkeletonExtractor(PlaneDataReadAccessSkeleton.class); } throw new UnsupportedOperationException("getSkeletonExtractor: " + c.getName()); }
private ResultSetExtractor<List<Map<String, Object>>> createResultSetExtractor() { return new ResultSetExtractor<List<Map<String, Object>>>() { @Override public List<Map<String, Object>> extractData(ResultSet rs) throws SQLException, DataAccessException { List<Map<String, Object>> ret = new ArrayList<>(); ResultSetMetaData rsmd = rs.getMetaData(); int numColumns = rsmd.getColumnCount(); while (rs.next()) { Map<String, Object> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (int i = 1; i <= numColumns; i++) { m.put(rsmd.getColumnLabel(i), rs.getObject(i)); } ret.add(m); } return ret; } }; }
@Override public String getSingleMarcData(String marcId) { String sql = " SELECT marc01,marc02,marc03 FROM " + dbUserPrefix + "marc_data WHERE marc_rec_no=? ORDER BY data_serial"; String marcStr = (String)getJdbcTemplate().query(sql, new Object[]{marcId},new ResultSetExtractor() { @Override public Object extractData(ResultSet rs) throws SQLException, DataAccessException { StringBuffer sb = new StringBuffer(); while(rs.next()){ if(StringUtils.isNoneBlank(rs.getString(1))) sb.append(rs.getString(1)); if(StringUtils.isNoneBlank(rs.getString(2))) sb.append(rs.getString(2)); if(StringUtils.isNoneBlank(rs.getString(3))) sb.append(rs.getString(3)); } return sb.toString(); } }); logger.debug(marcStr); return marcStr; }
@Override public String getItemLocationByMarcId(String marcId) { String sql = " SELECT distinct location from " + dbUserPrefix + "item WHERE book_stat_code>'40' and marc_rec_no=? "; String locaStr = (String)getJdbcTemplate().query(sql, new Object[]{marcId},new ResultSetExtractor() { @Override public Object extractData(ResultSet rs) throws SQLException, DataAccessException { List<String> locaList = new ArrayList<String>(); while(rs.next()){ locaList.add(StringUtils.trim(rs.getString(1))); } return StringUtils.join(locaList,","); } }); logger.debug("marcId:{}=>loca:{}",marcId,locaStr); return locaStr; }
/** * Performs a standard get by object identifier at instants. * * @param objectId the object identifier, not null * @param versionCorrection the version-correction locator, not null * @param extractor the extractor to use, not null * @param masterName a name describing the contents of the master for an error message, not null * @return the document, null if not found */ protected D doGetByOidInstants( final ObjectIdentifiable objectId, final VersionCorrection versionCorrection, final ResultSetExtractor<List<D>> extractor, final String masterName) { ArgumentChecker.notNull(objectId, "oid"); ArgumentChecker.notNull(versionCorrection, "versionCorrection"); ArgumentChecker.notNull(extractor, "extractor"); s_logger.debug("getByOidInstants {}", objectId); Timer.Context context = _getByOidInstantsTimer.time(); try { final VersionCorrection vc = (versionCorrection.containsLatest() ? versionCorrection.withLatestFixed(now()) : versionCorrection); final DbMapSqlParameterSource args = argsGetByOidInstants(objectId, vc); final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate(); final String sql = getElSqlBundle().getSql("GetByOidInstants", args); final List<D> docs = namedJdbc.query(sql, args, extractor); if (docs.isEmpty()) { throw new DataNotFoundException(masterName + " not found: " + objectId); } return docs.get(0); } finally { context.stop(); } }
/** * Performs a standard get by versioned unique identifier. * * @param uniqueId the versioned unique identifier, not null * @param extractor the extractor to use, not null * @param masterName a name describing the contents of the master for an error message, not null * @return the document, null if not found */ protected D doGetById(final UniqueId uniqueId, final ResultSetExtractor<List<D>> extractor, final String masterName) { ArgumentChecker.notNull(uniqueId, "uniqueId"); ArgumentChecker.notNull(extractor, "extractor"); s_logger.debug("getById {}", uniqueId); Timer.Context context = _getByIdTimer.time(); try { final DbMapSqlParameterSource args = argsGetById(uniqueId); final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate(); final String sql = getElSqlBundle().getSql("GetById", args); final List<D> docs = namedJdbc.query(sql, args, extractor); if (docs.isEmpty()) { throw new DataNotFoundException(masterName + " not found: " + uniqueId); } return docs.get(0); } finally { context.stop(); } }
/** * Performs a standard history search. * * @param <R> the document result type * @param request the request, not null * @param result the result to populate, not null * @param extractor the extractor to use, not null * @return the populated result, not null */ protected <R extends AbstractHistoryResult<D>> R doHistory( final AbstractHistoryRequest request, final R result, final ResultSetExtractor<List<D>> extractor) { ArgumentChecker.notNull(request, "request"); ArgumentChecker.notNull(result, "result"); ArgumentChecker.notNull(extractor, "extractor"); ArgumentChecker.notNull(request.getObjectId(), "request.objectId"); checkScheme(request.getObjectId()); s_logger.debug("history {}", request); Timer.Context context = _historyTimer.time(); try { final DbMapSqlParameterSource args = argsHistory(request); final String[] sql = {getElSqlBundle().getSql("History", args), getElSqlBundle().getSql("HistoryCount", args)}; searchWithPaging(request.getPagingRequest(), sql, args, extractor, result); return result; } finally { context.stop(); } }
/** * Searches for documents with paging. * * @param <T> the type of the document * @param pagingRequest the paging request, not null * @param sql the array of SQL, query and count, not null * @param args the query arguments, not null * @param extractor the extractor of results, not null * @param result the object to populate, not null */ protected <T extends AbstractDocument> void searchWithPaging( final PagingRequest pagingRequest, final String[] sql, final DbMapSqlParameterSource args, final ResultSetExtractor<List<T>> extractor, final AbstractDocumentsResult<T> result) { s_logger.debug("with args {}", args); final NamedParameterJdbcOperations namedJdbc = getJdbcTemplate(); if (pagingRequest.equals(PagingRequest.ALL)) { result.getDocuments().addAll(namedJdbc.query(sql[0], args, extractor)); result.setPaging(Paging.of(pagingRequest, result.getDocuments())); } else { s_logger.debug("executing sql {}", sql[1]); final int count = namedJdbc.queryForObject(sql[1], args, Integer.class); result.setPaging(Paging.of(pagingRequest, count)); if (count > 0 && pagingRequest.equals(PagingRequest.NONE) == false) { s_logger.debug("executing sql {}", sql[0]); result.getDocuments().addAll(namedJdbc.query(sql[0], args, extractor)); } } }
@SuppressWarnings("rawtypes") private ShardOperationProcessor<List> getNonAggregationProcessor(final RowMapper rowMapper) { final List<QueryCallable<List>> callableList = new ArrayList<ShardJdbcTemplate.QueryCallable<List>>(); ShardOperationProcessor<List> processor = new ShardOperationProcessor<List>() { @SuppressWarnings("unchecked") @Override public void addOperation(Shard shard, String sql, Object[] args) { ResultSetExtractor extractor = new RowMapperResultSetExtractor(rowMapper); QueryCallable<List> callable = new QueryCallable<List>(shard, sql, args, extractor); callableList.add(callable); } @Override public List processOperations() { List<List> rawResultList = ShardJdbcTemplate.this.executeQuery(callableList); return AggregationUtil.aggregateObjectList(rawResultList); } }; return processor; }
/** * Delegates to {@link JdbcOperations#query(JdbcTemplate, String, ResultSetExtractor)} where the {@link ResultSetExtractor} converts the {@link ResultSet} * into {@link JdbcStatementResultSet}. */ @Override public JdbcStatementResultSet query(JdbcTemplate jdbcTemplate, String sql, final Integer maxResult) { return jdbcOperations.query(jdbcTemplate, sql, new ResultSetExtractor<JdbcStatementResultSet>() { @Override public JdbcStatementResultSet extractData(ResultSet resultSet) throws SQLException, DataAccessException { JdbcStatementResultSet jdbcStatementResultSet = new JdbcStatementResultSet(); List<String> columnNames = getColumnNames(resultSet.getMetaData()); jdbcStatementResultSet.setColumnNames(columnNames); List<JdbcStatementResultSetRow> rows = getRows(resultSet, maxResult); jdbcStatementResultSet.setRows(rows); return jdbcStatementResultSet; } }); }
public List<Object[]> getTableReferences(String tablename){ List<Object[]> results = new ArrayList<Object[]>(); String sql = " SELECT TABNAME,CONSTNAME,FK_COLNAMES ,PK_COLNAMES FROM SYSCAT.REFERENCES where REFTABNAME ='"+tablename+"' " ; results=getJdbcTemplate().query(sql, new ResultSetExtractor<List<Object[]>>(){ public List<Object[]> extractData(ResultSet rs) throws SQLException, DataAccessException { List<Object[]>result=new ArrayList<Object[]>(); while(rs.next()){ Object[] oneResult = new Object[4]; for (int i = 1; i <= 4; i++) { oneResult[i - 1] = rs.getObject(i); } result.add(oneResult); } return result; } }); return results; }
public List<Object[]> createTableData(String tablename) { final int filedNum = getTableFieldNums(tablename); List<Object[]> results = new ArrayList<Object[]>(); String sql = " select * from " + tablename; results=getJdbcTemplate().query(sql, new ResultSetExtractor<List<Object[]>>(){ public List<Object[]> extractData(ResultSet rs) throws SQLException, DataAccessException { List<Object[]>result=new ArrayList<Object[]>(); while(rs.next()){ Object[] oneResult = new Object[filedNum]; for (int i = 1; i <= filedNum; i++) { oneResult[i - 1] = rs.getObject(i); if(rs.getObject(i)instanceof Clob){ oneResult[i - 1]=lobHandler.getClobAsString(rs, i); } } result.add(oneResult); } return result; } }); return results; }
public List<String> createIndexDDL(String tablename){ List<String>results; String sql = " SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name)FROM USER_INDEXES u WHERE table_name='" + tablename + "'"; results=getJdbcTemplate().query(sql, new ResultSetExtractor<List<String>>(){ public List<String> extractData(ResultSet rs) throws SQLException, DataAccessException { List<String>result=new ArrayList<String>(); while(rs.next()){ result.add(lobHandler.getClobAsString(rs, 1)) ; } return result; } }); return results; }
public <T> List<T> queryForList(String sql,Map<String,?> parameters, final int maxrows){ final RowMapper<T> mapper=new SingleColumnRowMapper<T>(); return this.namedParameterJdbcTemplate.query(sql, parameters, new ResultSetExtractor<List<T>>(){ @Override public List<T> extractData(ResultSet rs) throws SQLException, DataAccessException { List<T> data = new ArrayList<T>(); if(rs==null) return data; int rowNum = 0; while((maxrows>0 && rowNum<maxrows || maxrows<0) && rs.next()){ data.add(mapper.mapRow(rs, rowNum++)); } return data; } }); }