Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

StreamCurruptedException  RSS feed

 
Jahnvi Vyas
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.
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X 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: 9425
12
Linux Mac OS X 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: 9425
12
Linux Mac OS X 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!