[
https://issues.apache.org/jira/browse/CSV-138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14187640#comment-14187640
]
Bernd Eckenfels commented on CSV-138:
-------------------------------------
I just tried it with jTDS and MSSQL Driver, both do not advance in the
following code:
{code}
public static void main(String[] args) throws SQLException
{
final String user = "TEST";
final String pass = "TEST";
final String server = "localhost:8890";
Connection jtds =
DriverManager.getConnection("jdbc:jtds:sqlserver://"+server+"/" + user, user,
pass);
testNext(jtds, "jTDS");
Connection mssql =
DriverManager.getConnection("jdbc:sqlserver://" + server + ";databaseName=" +
user, user, pass);
testNext(mssql, "MS isql");
}
private static void testNext(Connection c, String name) throws
SQLException
{
try {
System.out.println("Trying " + name);
PreparedStatement ps = c.prepareStatement("SELECT *
from tTable");
ResultSet rs = ps.executeQuery();
System.out.println("before first? " +
rs.isBeforeFirst() +" " + rs.getRow());
ResultSetMetaData meta = rs.getMetaData();
System.out.println("before first (after getMeta)? " +
rs.isBeforeFirst() + " "+ rs.getRow());
int n = meta.getColumnCount();
System.out.println("before first (after getCol)? " +
rs.isBeforeFirst() + " " + rs.getRow() + " col#=" + n);
} finally { c.close(); }
}
{code}
resulting in:
{code}
Trying jTDS
before first? true 0
before first (after getMeta)? true 0
before first (after getCol)? true 0 col#=3
Trying MS isql
before first? true 0
before first (after getMeta)? true 0
before first (after getCol)? true 0 col#=3
{code}
I tried jTDS 1.3.1 and sqljdbc_4.0.2206.100_deu. I would agree, that if the
driver has a bug we might not need to support it. On the other hand we should
warn about it or try to support it (for example by checking isBeforeFirst()).
Alan, can you tell us which driver works and does not work? Did you use a
datasource or a pool?
> 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)