Shank Shank - 4 months ago 24
SQL Question

PrepareStatement Sql query Error

I can't seem to find the problem here.

The problem seems to occur at

"SZEDSP != ? "


I've tried the following with no success.


  1. "SZEDSP != ? "

  2. "SZEDSP <> ? "

  3. "SZEDSP != 'Y' "



Code:

PreparedStatement sqlQuery = null;
ResultSet results = null;

sqlQuery = con_data.prepareStatement("SELECT COUNT(*) AS rowcount FROM F47032"
+ "WHERE "
+ "SZEDSP != ? "
+ "AND SZEDOC = ?");
sqlQuery.setString(1, "Y");
sqlQuery.setString(2, documentNumbers.get(i));


Error:

DEBUG [AWT-EventQueue-0] DB2Handler [DB2Handler.java:1206] [SQL0104] Token != was not valid. Valid tokens: FOR USE SKIP WAIT WITH FETCH ORDER UNION EXCEPT OPTIMIZE.
java.sql.SQLException: [SQL0104] Token != was not valid. Valid tokens: FOR USE SKIP WAIT WITH FETCH ORDER UNION EXCEPT OPTIMIZE.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:646) ~[AsnInbound%20Downloader-Test.jar:JTOpen 6.7]

Answer

AFAIK most RDBMS allow using either != or <> for inequality. But I see a typo error of sorts in your prepared statement. There is no space between the table name and the WHERE keyword.

Currently your query appears to be this:

SELECT COUNT(*) AS rowcount FROM F47032WHERE SZEDSP != ? AND SZEDOC = ?

So you should add a space after the table name.

Comments