commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alan Stewart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CSV-138) CSVPrinter.printRecords(ResultSet) skips first row with SQLServer
Date Tue, 28 Oct 2014 04:09:34 GMT

    [ https://issues.apache.org/jira/browse/CSV-138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14186330#comment-14186330
] 

Alan Stewart commented on CSV-138:
----------------------------------

You are probably correct. I was debugging in Intellij and the first call to resultSet.getString(i)
in the for loop on line 480 of CSVPrinter was be evaluated as "2", being the primary key,
which was in fact the 2nd record in the table in a system test environment. It explained why
my local integration test kept failing with no records returned when I just created the one
record as test data. With the work around above,   resultSet.getString(i) brought back "1",
which is what I was expecting.

Our system is so tied to SQLServer it will be difficult to test against another database like
Postgres or MySql.  I will need to reproduce with a simple one table test case and then change
drivers to use against different databases. 

> CSVPrinter.printRecords(ResultSet) skips first row with SQLServer
> -----------------------------------------------------------------
>
>                 Key: CSV-138
>                 URL: https://issues.apache.org/jira/browse/CSV-138
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Printer
>    Affects Versions: 1.0
>            Reporter: Alan Stewart
>
> WIth SQLServer's 2012 jdbc driver 4.0, when I call CSVPrinter#printRecords with a java.sql.ResultSet,
the first row is not printed. It appears that the line
> {code}
> final int columnCount = resultSet.getMetaData().getColumnCount();
> {code} 
> positions the cursor on the first row and then when
> {code}
>  while (resultSet.next()) { ...
> {code}
> is called, the 2nd row onwards is what is getting outputted.
> As a workaround, I used :
> {code}
> final int columnCount = rs.getMetaData().getColumnCount();
> do {
>     for (int i = 1; i <= columnCount; i++) {
>         csvPrinter.print(rs.getString(i));
>     }
>     csvPrinter.println();
> } while (rs.next());
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message