DB2 query error during the retrieval of a CLOB field

后端 未结 2 870
孤城傲影
孤城傲影 2021-01-22 09:35

From Java I am doing the following query on DB2:

SELECT * FROM PRV_PRE_ACTIVATION WHERE TRANSACTION_ID = ?

The field TRANSACTION_ID

相关标签:
2条回答
  • 2021-01-22 10:18

    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.

    0 讨论(0)
  • 2021-01-22 10:25

    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.

    0 讨论(0)
提交回复
热议问题