ADTC
ADTC

Reputation: 10121

DB2 SqlException: SQL passed with no tokens (Error Code -4462)

Trying to use prepareStatement on a query from an XML file:

<sql><![CDATA[
  select MY_COLUMN from MY_TABLE where OTHER_COLUMN = ? 
]]>
</sql>

But I get this exception:

com.ibm.db2.jcc.am.SqlException: [jcc][t4][10234][10927][3.59.81] SQL passed with no tokens. ERRORCODE=-4462, SQLSTATE=null
        at com.ibm.db2.jcc.am.dd.a(dd.java:660)
        at com.ibm.db2.jcc.am.dd.a(dd.java:60)
        at com.ibm.db2.jcc.am.dd.a(dd.java:120)
        at com.ibm.db2.jcc.am.jb.v(jb.java:7334)
        at com.ibm.db2.jcc.am.jb.a(jb.java:2124)
        at com.ibm.db2.jcc.am.jb.prepareStatement(jb.java:754)

I read that this is because the SQL is not in a single line. Is that the cause?

I also read that in IBM Portal, you have to change db2_zos.DbDriverType from 2 to 4. But I think it's irrelevant to me as I don't use IBM Portal.

Nothing else useful turned up from Google. I would love to know the real cause of the error, and to find an easier fix than forcing all SQL to single line.

Code:

ArrayList arrList = new ArrayList();

String sSQL = queryManager.getSQL("QRY001");

Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
  conn = getConnection(); //a connection pool wrapper for java.sql.DriverManager.getConnection(...)
  ps = conn.prepareStatement(sSQL); // **** EXCEPTION OCCURS HERE

  ps.setInt(1, Integer.parseInt(otherColumn));
  rs = ps.executeQuery();
  while (rs.next())
  {
    arrList.add(rs.getString(1));
  }
} catch (Exception e) {
  e.printStackTrace();
  throw new OEException(e);
} finally {
  try {
    if (rs != null) {
      rs.close();
    }
    if (ps != null) {
      ps.close();
    }
    releaseConnection(conn);
  } catch (Exception e) {
    throw new CustomException(e);
  }
}
return arrList;

Upvotes: 2

Views: 15622

Answers (1)

Yue
Yue

Reputation: 1

Because the SQL execution has comments; Please refer to the official documentation https://www.ibm.com/support/pages/apar/PH14323

Also try writing it like this

<sql> 
  select MY_COLUMN from MY_TABLE where OTHER_COLUMN = ? 
</sql>

Upvotes: 0

Related Questions