DB2 query error during the retrieval of a CLOB field

五迷三道 提交于 2019-12-02 02:45:55

Try changing to a specified list of columns in the select list -- my guess is you have a user defined column type (or some other type) which is not supported by your driver. For example, does the statement

SELECT TRANSACTION_ID FROM PRV_PRE_ACTIVATION WHERE TRANSACTION_ID = ?

work? If so then start adding columns in and you will find the problem column.

I've came across this problem lately, and after some searching on web, I've came across this link: DB2 SQL error: SQLCODE: -270, SQLSTATE: 42997, SQLERRMC: 63 , which specifies this:

A column with a LOB type, distinct type on a LOB type, or structured type cannot be specified in the select-list of an insensitive scrollable cursor.

With help from an colleague, we came to this conclusion:

1, Q: When will you get this "SQLCODE=-204, SQLSTATE=42704" exception?

A: When a scrollable PreparedStatement is prepared & executed, yet there are [B|C]LOB fields exist in the select list. e.g.:

String strQuery = "SELECT NUMBER_FIELD, CHAR_FIELD, CLOB_FIELD FROM TABLE_NAME WHERE CONDITION IS TRUE;"
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, REsultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(strQuery); //and this exception will be thrown here

2, Q: So what's the solution if we want to get rid of it when [B|C]LOB fields are queried?

A: Try to use ResultSet.TYPE_FORWARD_ONLY while creating the query statement.e.g.:

stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

Or simply try this one:

stmt = conn.createStatement();

Note that the same rules apply to conn.prepareStatement() too. You may refer to Java API doc for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!