Menu

#780 SQL syntax exception on first rs.next() on result set from PreparedStatement (...ResultSet.TYPE_SCROLL_SENSITIVE..)

v2.x
open
nobody
None
1
2019-09-27
2019-09-27
No

using:

<dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
</dependency>

after executing this statement:
stm = conn.prepareStatement(sSQL, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

and then
while (rs.next())

an SQL syntax exception is thrown, with the hint: invalid systax near "NULLcolName"
where colName is indeed the name of a column in the table being queried, but is not actually one of the columns being selected.

I tracked the bug into net.sourceforge.jtds.jdbc.buildWhereClause

            if (currentRow[i] == null) {
                if (!"text".equals(columns[i].sqlType)
                        && !"ntext".equals(columns[i].sqlType)
                        && !"image".equals(columns[i].sqlType)
                        && columns[i].tableName != null) {
                    if (count > 0) {
                        sql.append(" AND ");
                    }
                    sql.append(columns[i].realName);
                    sql.append(" IS NULL");
                    **count++;**  // <--  you are missing this line
                }
            } else {

Discussion


Log in to post a comment.