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 Wed, 29 Oct 2014 03:24:34 GMT

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

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

My simple test also confirms no issue with the sqlserver 4.0 driver:
{code}
    public static void main(String[] args) {
        try (Connection con = DriverManager.getConnection("jdbc:sqlserver://HWBK-DSQN-DEV01:18889;Database=Nexus_138606",
"nexusWebapp", "nexusWebapp28");
             PreparedStatement ps = con.prepareStatement("select * from analytics.CollectionsStatCode");
             ResultSet rs = ps.executeQuery();
        ) {
            int columnCount = rs.getMetaData().getColumnCount();
            while (rs.next()) {
                for (int i = 1; i <= columnCount; i++) {
                    System.out.print(rs.getString(i) + ", ");
                }
                System.out.println("");
            }
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
    }
{code}
The first row is printed correctly and any number of calls to rs.getMetaData() prior to the
while statement does not change this.
I'm not sure what is going on now. The ResultSet I'm working with where I am seeing the problem
is given to me in a Spring RowCallbackHandler , method processRow(ResultSet), and I was passing
this to CSVPrinter.printRecords(rs)
I'm using a datasource configured in Tomcat but also have a junit integration test which uses
a commons-dbcp BasicDataSource (no pool)

I'll keep testing.


> 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