By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,191 Members | 1,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,191 IT Pros & Developers. It's quick & easy.

Problem while calling java stored procedure which connects to db2.

P: 2
Note: This problem occurred when I updated the JDK from 1.3.1 to 1.4.1 or 1.4.2.
Nothing else was changed in the code, other than updating the JDK on the database server (dbm cfg parm jdk_path) and recompiling/executing the code with 1.4.1 (deploying the newly compiled stored procedure code as well).

This is the original exception that I got before I tried any code modifications:

java.io.IOException: invalid offset/length
at COM.ibm.db2.app.BlobOutputStream.write(Lob.java:33 7)
at java.io.ObjectOutputStream$BlockDataOutputStream.w rite(ObjectOutputStream.java:1698)
at java.io.ObjectOutputStream.defaultWriteFields(Obje ctOutputStream.java:1416)
at java.io.ObjectOutputStream.defaultWriteObject(Obje ctOutputStream.java:398)
at java.lang.Throwable.writeObject(Throwable.java:679 )
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at java.io.ObjectStreamClass.invokeWriteObject(Object StreamClass.java:967)
at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1387)
at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1338)
at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1083)
at java.io.ObjectOutputStream.writeFatalException(Obj ectOutputStream.java:1449)
at java.io.ObjectOutputStream.writeObject(ObjectOutpu tStream.java:312)
at com.ibm.nzna.projects.common.storedProc.StoredProc Util.setObjectInBlob(StoredProcUtil.java:54)
at com.ibm.nzna.projects.common.storedProc.typeListRe ader.TypeListReader.readLists(TypeListReader.java: 166)

I get this exception when calling the stored procedure from within my java application. If I call the procedure from a DB2 command line (db2 call procedure QUEST.TypeListReader (1, 1, ?, ?)), the procedure executes properly. This leads me to believe that the problem therefore lies in trying to get the Blob object from the stored procedure return record. Here are snippets of the code used to call the procedure:

This is the method that calls the procedure:
Expand|Select|Wrap|Line Numbers
  1.  
  2.    private boolean readTypeListUsingStoredProcedure ( TypeListRec typeListRec, SQLMethod sqlMethod ) {   
  3.   boolean rc = false ;
  4.  
  5.   try {
  6.  CallableStatement stmt              = sqlMethod.createStoredProc ( "QUEST.TypeListReader", 4 ) ;
  7.  TypeListReaderRec typeListReaderRec = null ;
  8.  
  9.             /*-----------------------------------------------------------*/
  10.             /*                                                           */
  11. /*   Set up our parameters                                   */
  12.             /*                                                           */
  13.             /*-----------------------------------------------------------*/
  14. stmt.setInt ( 1, languageInd ) ;                       // Our Language Indicator
  15. stmt.setInt ( 2, typeListRec.getTypeListInd() ) ;      // Our Type List to read
  16. stmt.registerOutParameter ( 3, Types.LONGVARBINARY ) ; // The return Lob for TypeListReaderRec
  17. stmt.registerOutParameter ( 4, Types.LONGVARBINARY ) ; // The return Lob for StoredProcRetRec
  18.  
  19.             /*-----------------------------------------------------------*/
  20.             /*                                                           */
  21.             /*   Execute                                                 */
  22.             /*                                                           */
  23.             /*-----------------------------------------------------------*/
  24.     stmt.execute() ;              // make the call to the stored procedure                       
  25.  
  26.             /*-----------------------------------------------------------*/
  27.             /*                                                           */
  28.             /*   Get the StoredProcRec from the Lob                      */
  29.             /*                                                           */
  30.             /*-----------------------------------------------------------*/
  31.             StoredProcRec retRec = (StoredProcRec)StoredProcUtil.getObjectFromStatement ( stmt, 4 ) ;
  32.  
  33.             if ( ( retRec != null ) && ( retRec.error ) ) {
  34.                LogSystem.log ( 1, retRec.errorStr ) ;
  35.             }
  36.  
  37.             /*-----------------------------------------------------------*/
  38.             /*                                                           */
  39.             /*   Otherwise continue                                      */
  40.             /*                                                           */
  41.             /*-----------------------------------------------------------*/
  42.             else {
  43.  
  44.                /*-----------------------------------------------------------*/
  45.                /*                                                           */
  46.                /*   Get our return object                                   */
  47.                /*                                                           */
  48.                /*-----------------------------------------------------------*/
  49.                typeListReaderRec = (TypeListReaderRec) StoredProcUtil.getObjectFromStatement ( stmt, 3 ) ;  
  50.                getInstance().setTypeList ( typeListRec.getTypeListInd(), typeListReaderRec.retVec ) ;                                   
  51.                rc = true ;
  52.             }
  53.  
  54.       } catch ( Exception e ) {
  55.          sqlMethod.rollBack() ;
  56.          LogSystem.log ( 1, e, false ) ;
  57.       }
  58.  
  59.       return ( rc ) ;
  60.  
  61.    }
  62.  
  63.  
  64.  
  65. This is the method that is defined as the procedure's external name (TypeListReader!readlists (...):
  66.  
  67.  
  68.  
  69.     public void readLists ( int languageInd, int typeListInd, Blob retTypeListReaderRec, Blob storedProcRetRec ) throws Exception  {                            
  70.  
  71.       try {
  72.  
  73.          /*-----------------------------------------------------------*/
  74.          /*                                                           */
  75.          /*   Get our connection to DB/2                              */
  76.          /*                                                           */
  77.          /*-----------------------------------------------------------*/
  78.          con = getConnection() ;         
  79.  
  80.          /*-----------------------------------------------------------*/
  81.          /*                                                           */
  82.          /*   Initialize our Type List Reader Record                  */
  83.          /*                                                           */
  84.          /*-----------------------------------------------------------*/
  85.          typeListReaderRec = new TypeListReaderRec () ;                                                    
  86.  
  87.          readLists ( languageInd, typeListInd, con, typeListReaderRec) ;
  88.  
  89.          /*-----------------------------------------------------------*/
  90.          /*                                                           */
  91.          /*   Write out our TypeListReaderRec                         */
  92.          /*                                                           */
  93.          /*-----------------------------------------------------------*/
  94.  
  95.  
  96.  
  97.  
  98. *** I create a new Blob object from COM.ibm.db2.app.Lob, then pass it to my setObjectInBlob method along with typeListReaderRec, which contains the data I want to pass back to the client ***
  99.  
  100.  
  101.  
  102.  
  103.          retTypeListReaderRec = Lob.newBlob() ;
  104.          StoredProcUtil.setObjectInBlob ( retTypeListReaderRec, typeListReaderRec );  //This is the method call that fails
  105.          set ( 3, retTypeListReaderRec ) ;
  106.  
  107.  
  108.       } catch ( Exception e ) {
  109.          StoredProcUtil.writeException ( e, returnRec ) ;
  110.       }
  111.  
  112.       /*-----------------------------------------------------------*/
  113.       /*                                                           */
  114.       /*   Commit                                                  */
  115.       /*                                                           */
  116.       /*-----------------------------------------------------------*/
  117.       con.commit() ;
  118.       con.close() ;
  119.  
  120.       /*-----------------------------------------------------------*/
  121.       /*                                                           */
  122.       /*   Write out our return information                        */
  123.       /*                                                           */
  124.       /*-----------------------------------------------------------*/
  125.       storedProcRetRec = Lob.newBlob() ;
  126.       StoredProcUtil.setObjectInBlob ( storedProcRetRec, returnRec ) ;
  127.  
  128.       set ( 4, storedProcRetRec ) ;
  129.  
  130.    }
  131.  
  132. This is the method that places the return object into the blob:
  133.  
  134.     public static void setObjectInBlob ( Blob blob, Object object ) throws Exception {
  135.         ObjectOutputStream s = new ObjectOutputStream ( blob.getOutputStream() ) ;
  136.  
  137.         s.writeObject ( object ) ;  // This is the line that actually fails
  138.         s.flush() ;
  139.         s.close() ;
  140.     }
  141.  
  142.  
  143. This is how TypeListReaderRec is defined (the object I am passing back to the client).  It is just a collection of Vector objects:
  144. package com.ibm.nzna.projects.common.storedProc.typeListReader ;
  145. import java.util.* ;
  146.  
  147. public class TypeListReaderRec implements java.io.Serializable {
  148.  
  149.     public Vector retVec = null ;
  150.  
  151.     public Vector countryCodeVec    = null ;
  152.     public Vector geographyVec      = null ;
  153.     public Vector docTypeVec        = null ;
  154.     public Vector docClassVec       = null ;
  155.     public Vector customViewVec     = null ;
  156.     public Vector workVec           = null ;
  157.     public Vector authVec           = null ;
  158.     public Vector metricVec         = null ;
  159.     public Vector languageVec       = null ;
  160.     public Vector fsVec             = null ;
  161.  
  162. } /* TypeListReaderRec */
Jun 16 '07 #1
Share this Question
Share on Google+
1 Reply


P: 2
This problem occurred when I updated the JDK from 1.3.1 to 1.4.1 or 1.4.2.
Nothing else was changed in the code, other than updating the JDK on the database server (dbm cfg parm jdk_path) and recompiling/executing the code with 1.4.1 (deploying the newly compiled stored procedure code as well).

This is the original exception that I got before I tried any code modifications:

java.io.IOException: invalid offset/length
at COM.ibm.db2.app.BlobOutputStream.write(Lob.java:33 7)
at java.io.ObjectOutputStream$BlockDataOutputStream.w rite(ObjectOutputStream.java:1698)
at java.io.ObjectOutputStream.defaultWriteFields(Obje ctOutputStream.java:1416)
at java.io.ObjectOutputStream.defaultWriteObject(Obje ctOutputStream.java:398)
at java.lang.Throwable.writeObject(Throwable.java:679 )
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at java.io.ObjectStreamClass.invokeWriteObject(Object StreamClass.java:967)
at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1387)
at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1338)
at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1083)
at java.io.ObjectOutputStream.writeFatalException(Obj ectOutputStream.java:1449)
at java.io.ObjectOutputStream.writeObject(ObjectOutpu tStream.java:312)
at com.ibm.nzna.projects.common.storedProc.StoredProc Util.setObjectInBlob(StoredProcUtil.java:54)
at com.ibm.nzna.projects.common.storedProc.typeListRe ader.TypeListReader.readLists(TypeListReader.java: 166)

Please let me know if more clarifications are required
Jun 21 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.