IBM Support

IC62554: CLASSCASTEXCEPTION WHEN CALLING EXECUTEBATCH() IF A STATEMENT PARAMETER THAT GETS CAST TO DECIMAL WAS SET USING SETLONG()

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • Using the JCC driver (Java Common Client, also known as
    IBM Data Server Driver for JDBC and SQLJ),
    when you call the executeBatch() method of
    PreparedStatement to execute certain INSERT statements, and
    you have used the setLong() method of PreparedStatement to set
    the value of a statement parameter that is cast to
    DECIMAL, a java.lang.ClassCastException occurs.
    
    The problem occurs only if all the following conditions are
    true:
    - the JCC property deferPrepares=true
    - the database server is DB2 on zOS
    - the INSERT statement is of the form
       INSERT INTO ... SELECT ... CAST(? AS DECIMAL(...))"
    
    
    
    The problem can be reproduced by creating a table like this:
    
     create table tab1(col1 decimal(18, 0));
    
    
    and then running a program like this:
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    
    public class TestPrepare
    {
        public static void main(String[] args)
        {
            Connection cnn = null;
            PreparedStatement ps = null;
    
            try
            {
    
                Class.forName("com.ibm.db2.jcc.DB2Driver");
    
                cnn = DriverManager.getConnection(
                 "<connection string>","<username>","<password>");
    
                ps = cnn.prepareStatement(
                 "insert into tab1(col1) select cast(? as
                   decimal(18,0)) from tab1"
                 );
                ps.setLong(1, 6);
    
                ps.addBatch();
                ps.executeBatch();
            }
    
            catch (Exception e)
            {
                if (e.getMessage() != null)
                {
                    System.out.println(e.getMessage());
                }
                e.printStackTrace();
            }
            finally
            {
               if (ps != null)
                {
                    try
                    {
                        ps.close();
                    }
                    catch (SQLException e) {}
                }
                if (cnn != null)
                {
                    try
                    {
                        cnn.close();
                    }
                    catch (SQLException e) {}
                }
            }
        }
    }
    

Local fix

  • To set the value of the statement parameter, call
    setBigDecimal() or setObject() instead of setLong().
    
    That means, in the example program, replace the line:
     ps.setLong(1, 6)
    with:
     ps.setBigDecimal(1, new java.math.BigDecimal(6));
    or:
     ps.setObject(1, "6");
    

Problem summary

  • ****************************************************************
    * USERS AFFECTED:                                              *
    * Users of the IBM Data Server Driver for JDBC and SQLJ (also  *
    * called the JCC driver) who connect to DB2 on zOS             *
    ****************************************************************
    * PROBLEM DESCRIPTION:                                         *
    * See Error Description                                        *
    ****************************************************************
    * RECOMMENDATION:                                              *
    * .                                                            *
    ****************************************************************
    

Problem conclusion

  • Problem was first fixed in Version 9 Fix Pack 9
    

Temporary fix

  • As a workaround, to set the value of the statement parameter,
    call setBigDecimal() or setObject() instead of setLong().
    
    That means, in the example program, replace the line:
    ps.setLong(1, 6)
    with:
    ps.setBigDecimal(1, new java.math.BigDecimal(6));
    or:
    ps.setObject(1, "6");
    

Comments

APAR Information

  • APAR number

    IC62554

  • Reported component name

    DB2 FOR LUW

  • Reported component ID

    DB2FORLUW

  • Reported release

    910

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2009-08-14

  • Closed date

    2011-02-02

  • Last modified date

    2011-02-08

  • APAR is sysrouted FROM one or more of the following:

    IC62493

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    DB2 FOR LUW

  • Fixed component ID

    DB2FORLUW

Applicable component levels

  • R910 PSN

       UP

  • R950 PSN

       UP

  • R970 PSN

       UP

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"9.1","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
08 February 2011