[
https://issues.apache.org/jira/browse/CSV-313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17888469#comment-17888469
]
Mikhail T. commented on CSV-313:
--------------------------------
{quote}Please use {{CSVPrinter.getRecordCount()}}
{quote}
That would work too, thanks. However, I was going to suggest a new form for the
same method:
{code:java}
/**
* Prints all the objects in the given JDBC result set.
*
* @param resultSet
* The values to print.
* @param maxRows
* Do not print more than this many rows. Pass -1 or
Long.MAX_VALUE for no limit
*
* @return
* The number of records actually processed, which may be
fewer, than maxRows
* @throws IOException
* If an I/O error occurs.
* @throws SQLException
* Thrown when a database access error occurs.
*/
public long printRecords(final ResultSet resultSet, long maxRows) throws
SQLException, IOException {
...
{code}
This would act somewhat similar to {{fwrite()}} and benefit those of us, who
have to feed CSV-files to systems with limited number of rows. The current
Excel, for example, is limited to 1mln rows, and the earlier versions, I
recall, maxed out at 32k...
The new signature would allow changing the return type too...
> Add CSVPrinter.getRecordCount()
> -------------------------------
>
> Key: CSV-313
> URL: https://issues.apache.org/jira/browse/CSV-313
> Project: Commons CSV
> Issue Type: New Feature
> Components: Printer
> Reporter: Mikhail T.
> Assignee: Gary D. Gregory
> Priority: Major
> Fix For: 1.13.0
>
> Attachments: printRecords.patch.txt
>
>
> The {{printRecords(ResultSet)}} variant is very convenient for outputting
> _all_ of a query's results in a single line of code.
> Unfortunately, this provides no way to obtain the number of records printed.
> See [this StackOverflow
> question|https://stackoverflow.com/questions/79071049/], for example.
> A forward-only result-set is "done" after the method returns...
> The simplest way to address this shortcoming would be for the
> {{printRecords()}} to start returning a {{long}} (for lack of {{{}size_t{}}})
> instead of {{{}void{}}}, indicating the number of records printed.
> This seems like an easy fix, for certainly the number of output rows is
> _known_ inside the method...
--
This message was sent by Atlassian Jira
(v8.20.10#820010)