home clear 64x64
en blue 200x116 de orange 200x116 info letter User
suche 36x36
Latest versionsfixlist
11.1.0.7 FixList
10.5.0.9 FixList
10.1.0.6 FixList
9.8.0.5 FixList
9.7.0.11 FixList
9.5.0.10 FixList
9.1.0.12 FixList
Have problems? - contact us.
Register for free anmeldung-x26
Contact form kontakt-x26

DB2 - Problem description

Problem IC62493 Status: Closed

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

product:
DB2 FOR LUW / DB2FORLUW / 950 - DB2
Problem 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) {} 
            } 
        } 
    } 
}
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:                                              * 
* .                                                            * 
****************************************************************
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");
available fix packs:
DB2 Version 9.5 Fix Pack 6a for Linux, UNIX, and Windows
DB2 Version 9.5 Fix Pack 7 for Linux, UNIX, and Windows
DB2 Version 9.5 Fix Pack 8 for Linux, UNIX, and Windows
DB2 Version 9.5 Fix Pack 9 for Linux, UNIX, and Windows
DB2 Version 9.5 Fix Pack 10 for Linux, UNIX, and Windows

Solution
Problem was first fixed in Version 9.5 Fix Pack 5
Workaround
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");
BUG-Tracking
forerunner  : APAR is sysrouted TO one or more of the following: IC62554 IC62555 
follow-up : 
Timestamps
Date  - problem reported    :
Date  - problem closed      :
Date  - last modified       :
12.08.2009
26.01.2011
01.02.2011
Problem solved at the following versions (IBM BugInfos)
9.5.FP5
Problem solved according to the fixlist(s) of the following version(s)
9.5.0.5 FixList