SQL syntax exception on first rs.next() on result set from PreparedStatement...
Brought to you by:
ickzon
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 {