Com.sun.jdi.InvocationException method call occurred. when reading from Object Stream

I have code where I write a hashMap list in a database column, where the column type is BLOB. Previously, the code was written to insert a hash map into a database, which I am modifying to insert a hash map.

The read and write code is as follows: -

WRITE: -

Object temp = attributes.get(columnName);
        if (temp instanceof List && temp != null) {
                        List extraAttributes = (ArrayList) temp;
            resultStmt.setBytes(currentIndex, createByteArray(extraAttributes));                                

                        }



private byte [] createByteArray( Object obj)
    {
        byte [] bArray = null;
        try
        {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream objOstream = new ObjectOutputStream(baos);
                objOstream.writeObject(obj);
                bArray = baos.toByteArray();
        }
        catch (Exception e)
        {
      TraceDbLog.writeError("Problem in createByteArray", e);

        }

                return bArray;

    }

READ : - Here TableType.Map is not java.util.Map, enter its declaration to determine the type of column in the database schema.

else if (columnType.equals(TableType.MAP))
            {
                if (resultSet.getBytes(columnName) != null)
                {
            resultMap.put(columnName, readBytes(resultSet, columnName));
                            }
                        }

private Object readBytes (ResultSet rs, String columnName)
    throws SQLException
    {
        ObjectInputStream ois  = null;
        byte [] newArray;
        Object obj = null;

        try
        {
            newArray = rs.getBytes(columnName);

            ois = new ObjectInputStream (new ByteArrayInputStream(newArray));
            obj = ois.readObject ();
        }
        catch (Exception e)
        {
            throw new SQLException (getClass() + ":readBytes: " + e);
        }
        finally
        {
            if (ois != null)
            {
                try
                {
                    ois.close ();
                }
                catch (IOException e)
                {
                    throw new SQLException (getClass() + ":readBytes: " + e);
                }
            }
        }

        return obj;

    }

PROBLEM

The recording has no related problems. When I am about to perform a read operation,

obj = ois.readObject ();

On this line, obj comes as: com.sun.jdi.InvocationException occurred invoking method.

So there is some problem when we read data from a stream.

Please help what I did wrong here

thank

0

Source: https://habr.com/ru/post/1598900/


All Articles