473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem while calling java stored procedure which connects to db2.

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
1 2920
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

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

Similar topics

4
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
2
by: Marc Stiegele | last post by:
Hello, I have a problem with the IBM DB2 UDB XML Extender. I`m working on a iSeries 400 server (AS/400, V5R1) with a integrated DB2 (my client is NT 4.0 Service Pack 1 with JDK1.1.8). I want to...
5
by: Alex | last post by:
Hi all, I'm sure this is really really easy but I do need some help. I'm writing a java stored prcedure to manage the assignment of IP addresses to mac addresses for a network device database...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
0
by: Roman Prigozhin | last post by:
HI All, I have a problem with calling stored procedure in multithreaded environment. This procedure utilizes session table to collect data and cursor to return it back to java application . When...
4
by: nishi57 | last post by:
I hope I can get some help regarding this issue, which has been going on for a while. I have a desktop user who is having problem running "Stored Procedures". The DB2 Connect application works fine...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
3
by: mgsmario | last post by:
Hi Guys I have an ASP application that connects to an Oracle database, right now I'm trying to connect this same ASP application to a DB2 database (Express-C, version 9.5.0). I'm in the process...
0
by: mgsmario | last post by:
Hi Guys I have an ASP application that connects to an Oracle database, right now I'm trying to connect this same ASP application to a DB2 database (Express-C, version 9.5.0). I'm in the process...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.