0

Hey all I have the following SQL query:

Class.forName("oracle.jdbc.driver.OracleDriver");
PreparedStatement stmt = con.prepareStatement("SELECT " +
                                                "DECODE(MAX(ID), NULL, 'NO', 'YES') BOOL_VAL " +
                                              "FROM " +
                                                "MASTERNICSDB " + 
                                              "WHERE " + 
                                                "FTAG = ? " +
                                              "AND " + 
                                                "BADGENUM IS ?");
stmt.setString(1, System.getenv("COMPUTERNAME").toUpperCase());
stmt.setNull(2, Types.VARCHAR);
ResultSet rs = stmt.executeQuery();
rs.next();

The issue with the above is that it keeps throwing:

ORA-00908: missing NULL keyword

I have tried all of the following:

stmt.setNull(2, Types.VARCHAR);
stmt.setString(2, "NULL");
stmt.setNull(2, oracle.jdbc.OracleTypes.VARCHAR);
stmt.setObject(2, null);

None of which seem to work. They all get the same error as above.

However, if I place the values inside the query all is fine - but I don't want to do that due to SQL injection and all that fun stuff.

StealthRT
  • 10,108
  • 40
  • 183
  • 342

0 Answers0