java.io.StreamCorruptedException:无效的流标题:4920616D

时间:2015-12-23 11:57:24

标签: java jdbc file-io

嗨当我试图读取blob获取异常时。我发布了如何写入数据库并向db提出建议,这引起了太多问题..

ava.io.StreamCorruptedException: invalid stream header: 4920616D
                at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:782)
                at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
                at com.jiit.jfx.persistence.TypeHelper.readBlob(TypeHelper.java:137)
                at com.jiit.jfx.persistence.TypeHelper.get(TypeHelper.java:84)
                at com.jiit.jfx.persistence.dataaccess.OracleSQLQuery.get(OracleSQLQuery.java:116)
                at com.jiit.jfx.persistence.dataaccess.OracleSQLQuery.doOperation(OracleSQLQuery.java:65)
                at com.jiit.jfx.persistence.dataaccess.AbstractDAO.execute(AbstractDAO.java:181)
                at com.jiit.jfx.persistence.dataaccess.AbstractDAO.executeSQL(AbstractDAO.java:208)
                at 

com.jiit.ngcs.mx.server.model.rail.ASMMessageStore.getASMMessageStore(ASMMessageStore.java:196)




    enter code here

    Reading BOLB :

        public static Blob createBlob(Object serializable) throws PersistenceException{
            try {
                ByteArrayOutputStream bStream = new ByteArrayOutputStream();
                ObjectOutputStream oStream = new ObjectOutputStream(bStream);
                oStream.writeObject(serializable);
                oStream.flush();
                oStream.close();
                return createBlob(bStream.toByteArray());
            } catch (Exception e) {
                throw new PersistenceException(e.getMessage());
            }
        }
        in TypeHelper.java -- > createBlob


        private static Object readBlob(int index, ResultSet rs) throws SQLException {
            try {
                InputStream is = rs.getBinaryStream(index);
                if(is != null) {
                    ObjectInputStream os = new ObjectInputStream(is);
                    return os.readObject();
                }
                return null;
            } catch (IOException e) {
                e.printStackTrace();
                throw new SQLException(e.getMessage());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
                throw new SQLException(e.getMessage());
            }

尝试了stackoverflow和其他博客中给出的所有案例。仍然不明白确切的问题。

1 个答案:

答案 0 :(得分:4)

让我们从4920616D开始。如果你把它解码为ASCII字符,你会得到&#34;我是&#34; ......英文文本。现在这可能是巧合,但我们假设它不是。

什么可能导致文本出现在您期望序列化对象的位置?

嗯,有一种可能性是你得到了结果集索引值错误。如果结果集中的索引1对应于CHAR或VARCHAR或类似字段中的值,则JDBC驱动程序可以返回&#34;二进制流&#34;由一堆编码文本组成。您可以看到数据库可用于存储文本的多种字符编码方案的字符,包括ASCII,LATIN-1和UTF-8。