Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

StreamCurruptedException

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am developing web application with JSP and MySql(as back-end). One of the column type is blob in my table. I am inserting blob values to database with using setBlob(..) method.

I want to retrive this value in ObjectInputStream. Now when I am doing this I am getting error :- java.io.StreamCurruptedException : Invalid stream header. The code is as follows:

InputStream is = rs.getBinaryStream("mykey");
--> ObjectInputStream ois = new ObjectInputStream(is);

..where rs is ResultSet variable and mykey is my field from which value is to be retrived.

At shown arrow I am getting above error. Can anybody tell, why it happens??

Thanks..

Jahnvi.
 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The probable cause of this exception is that you did not write the value to the database using an ObjectOutputStream. The OOS writes a header to the stream to mark it as a serialized object. The "invalid stream header" in your stack trace indicates that this header is either corrupt or does not exist.
 
Jahnvi Vyas
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe.

Even I was thinking the same thing. But I dont know how to write to a ObjectOutputStream. Let me tell you my problem in detail.

I have a byte array. I created a ObjectOutputStream and I am writing this array in OOS by using write method. But how to pass it to sql querry. Because I have to store this data to database. The field type is blob.
Do you know how can it be achieved??

Thanks..

Jahnvi.
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using ObjectOutputStream to write a byte array? A BLOB is simply a stream of bytes. Have a look at java.sql.Blob.
 
Jahnvi Vyas
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

I know that reading/writing in blob is very easy. It can be done with setBlob and getBlob. But I want to store Public Key and Private Key in database and I want to retrive these keys as it is that is as a Key because I am using it further to sign message. And there are no ways to store key in database rather than bytes[] or Blob. I tried for Blob but when I retrive key as Blob there are no ways to further type cast or convert it into key.

So, what I want to do is... I will retrive Key from InputStream and this InputStream I will pass to ObjectInputStream. Now from here I will extract it as Object and so I can convert it as Key.

I hope now you got what actually I want to do. I tried to store and retrive these in files rather than database, that time it works. But I want to store into database.

Please, if you have any suggestion then I will be greatful.

Thanks..

Jahnvi.
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jahnvi Vyas:
I know that reading/writing in blob is very easy. It can be done with setBlob and getBlob.



So you serialize the Key object the same way would to a file, only into a Blob. I don't understand where your problem is. Perhaps you should show us the code you are using to save the Key.
 
Jahnvi Vyas
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe.
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic