Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Posts
    1

    Unanswered: DB2 Lob Locator Problem

    Hi,
    We are connecting to DB2 database using TopLink3.6. We have the following table with blob columns.

    CREATE TABLE Table1 (
    col1 DECIMAL(10) NOT NULL,
    blob1 BLOB(164000),
    col2 DECIMAL(10) NOT NULL,
    blob2 BLOB(164000)
    )

    This works fine with JDBC Level 1 driver. But, while using JDBC Level 2 driver, We are getting the following exception;

    EXCEPTION [TOPLINK-4002] (3.6 JDK1.2): TOPLink.Public.Exceptions.DatabaseException
    EXCEPTION DESCRIPTION: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0423N Locator va
    riable "1" does not currently represent any value. SQLSTATE=0F001

    INTERNAL EXCEPTION: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0423N Locator varia
    ble "1" does not currently represent any value. SQLSTATE=0F001

    ERROR CODE: -423
    at TOPLink.Public.Exceptions.DatabaseException.sqlExc eption(DatabaseException.java:221)
    at TOPLink.Private.Helper.ConversionManager.convertOb jectToByteArray(ConversionManager.java:
    212)
    at TOPLink.Private.Helper.ConversionManager.convertOb ject(ConversionManager.java:81)
    at TOPLink.Private.DatabaseAccess.DatabasePlatform.co nvertObject(DatabasePlatform.java:594)
    at TOPLink.Public.Mappings.SerializedObjectMapping.ge tAttributeValue(SerializedObjectMapping
    .java:43)
    at TOPLink.Public.Mappings.DirectToFieldMapping.value FromRow(DirectToFieldMapping.java:474)
    at TOPLink.Public.Mappings.DatabaseMapping.readFromRo wIntoObject(DatabaseMapping.java:808)
    at TOPLink.Private.Descriptors.ObjectBuilder.buildAtt ributesIntoObject(ObjectBuilder.java:16
    8)
    at TOPLink.Private.Descriptors.ObjectBuilder.buildObj ect(ObjectBuilder.java:320)
    at TOPLink.Private.Descriptors.ObjectBuilder.buildObj ectsInto(ObjectBuilder.java:368)
    at TOPLink.Public.QueryFramework.ReadAllQuery.execute (ReadAllQuery.java:368)
    at TOPLink.Public.QueryFramework.DatabaseQuery.execut e(DatabaseQuery.java:394)
    at TOPLink.Public.QueryFramework.ReadQuery.execute(Re adQuery.java:99)
    at TOPLink.Public.PublicInterface.Session.internalExe cuteQuery(Session.java:1628)
    at TOPLink.Public.ThreeTier.ServerSession.internalExe cuteQuery(ServerSession.java:543)
    at TOPLink.Public.PublicInterface.Session.executeQuer y(Session.java:921)
    at TOPLink.Private.Indirection.QueryBasedValueHolder. instantiate(QueryBasedValueHolder.java:
    45)
    at TOPLink.Private.Indirection.DatabaseValueHolder.ge tValue(DatabaseValueHolder.java:62)
    at TLTable1.toString(Unknown Source)

    I used the Blob.getBlob() in my sample application to get that table data and that retrieves fine(ie, without using toplink) ..

    have anybody faced this already or someone has an answer for it.

    Thanks in advance for the help!!

    -Senthil.

  2. #2
    Join Date
    Jul 2002
    Posts
    1

    Angry

    I think this problem has nothing to do with toplink or the jdbc driver version. I get the same error message in my application as soon as the blob value is a greater than some value ( i don't know the limit ). I searched for a lot of days all db2 sites for help -> nothing but this thread in whole internet about reading blob values with java.

    All examples from ibm one of the 2 possible code fragments :
    ResultSet.getBinaryStream(...) or
    ResultSet.getBlob(...)

    both ideas do not work as soon the data to be read is to large, so i think, that there is a buffer overflow with large blob objects or the curser get closed to soon ?!?

    Have you found any work around or found a solution for your problem so far ?

    Here is a code fragment of my implementation:
    public Vector getObjectBlob(String sql, int column_number, String column_name, int MAX)
    throws java.sql.SQLException, java.io.IOException {
    Vector result=new Vector();
    reconnect(10);
    // create Statement object
    Statement stmt = con.createStatement();

    // create a ResultSet object by executing query
    ResultSet rs = stmt.executeQuery(sql);

    // create ResultMetaData object to verify target column's SQL datatype
    ResultSetMetaData rsmd;

    while (rs.next()) {
    Blob blobObj=null;
    Object obj=null;
    if (column_name!=null)
    // here the exception is thrown!
    blobObj = rs.getBlob(column_name);
    else
    blobObj = rs.getBlob(column_number);

    if (blobObj == null) {
    System.err.println("no blob value found");
    } else {
    // Retrieve meta data for the result set
    rsmd = rs.getMetaData();
    System.out.println("reading from type "+rsmd.getColumnTypeName(1));
    byte[] buffer = new byte[MAX];

    InputStream is = blobObj.getBinaryStream();
    is.read(buffer);
    File tmp=File.createTempFile("ObjectBlob",".tmp");
    FileOutputStream out=new FileOutputStream(tmp);
    out.write(buffer,0,buffer.length);
    out.close();
    ObjectInputStream in=new ObjectInputStream(new FileInputStream(tmp));
    try {
    obj=in.readObject();
    } catch (Exception e) {
    System.err.println("No Object found in Blob value");
    }
    in.close();
    tmp.delete();
    }
    result.addElement(obj);
    }
    rs.close();
    stmt.close();
    return result;
    }


    Please notify me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •