Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting NotSerializableException while calling oracle stored procedure with BLOB as in parameter  RSS feed

 
Aniket V Kulkarni
Greenhorn
Posts: 5
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am working on struts-1.x application. I want to insert CSV file as BLOB in oracle database table. I cant update the oracle table directly. They want me to call oracle store procedure with IN parameter as BLOB. I am doing following things:

FormFile uploadFile = (FormFile)uploadForm.get("uFile");
InputStream inputFile = uploadFile.getInputStream();
String fileName = uploadFile.getFileName();
..
CallableStatement stmt = conn.prepareCall("{UPLOAD_FILE(?,?,?)}");
stmt.setBinaryStream(1, inputFile);
stmt.setString(2,fileName);
stmt.registerOutParameter(3, Types.VARCHAR);

But when I deployed this struts application on OC4J application server and run it, its giving following exception:
com.evermind.server.rmi.OrionRemoteException: Error marshalling objects: java.io.NotSerializableException: java.io.ByteArrayInputStream..

It looks like struts application use RMI fremwork and its unable to serialize InputStream object inputFile as it is not serilazable object.
Please anybody can help me in achiving my purpose of inserting whole CSV file as a BLOB in oracle database.

Thanks,
Aniket
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I don't use struts or Oracle so this is a stab in the dark but can't you read in the file yourself, store the input in a byte array (or in whatever format is required) and pass the byte array to the database.
 
Aniket V Kulkarni
Greenhorn
Posts: 5
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,

Thanks a lot for your reply.
I tried the way you said. I converted the InputStream to byte array and passed it to the oracle but still getting the same error. I does the following things:

FormFile uploadFile = (FormFile)uploadForm.get("uFile");
InputStream inputFile = uploadFile.getInputStream();
String fileName = uploadFile.getFileName();

long streamLength = inputFile.available();
byte[] bytes = new byte[(int) streamLength];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
while ((bytesRead = fileData.read(bytes)) != -1)
{
output.write(bytes, 0, bytesRead);
}
..
CallableStatement stmt = conn.prepareCall("{UPLOAD_FILE(?,?,?)}");
stmt.setBytes(1,output.toByteArray());
stmt.setString(2,fileName);
stmt.registerOutParameter(3, Types.VARCHAR);

I passed this byte array to the database but I guess the struts framework internally uses the RMI framework and RMI methods unable to serilize byte array or InputStream and causing the exception.
I tried some other methods of CallableStatement like
stmt.setBinaryStream(int arg0, InputStream arg1),
stmt.setBlob(int arg0, InputStream arg1, long arg2)
but no help. Still getting the same exception.

THanks,
Aniket
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand how you can be getting the same exception when you are no longer passing in an input stream unless UPLOAD_FILE is causing it. What does UPLOAD_FILE do btw and does it accept a byte array as the first parameter, you passed it an input stream in your first post?
 
Aniket V Kulkarni
Greenhorn
Posts: 5
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,

Thanks for your reply.

My issue is resolved. Atleast I am not getting that NotSerializableException. Actually issue was with my java Dto(data transfer object). In my web application, from my web layer to business layer I am transfereing my file data(i.e. InputStream) by wrapping it into a java object(POJO). While transfering these objects from web layer to business layer, my application tries to serialize these objects. As my java object was containing the InputStream and InputStream is not serializable, thats why it was throwing NotSerializableException. To solve this issue I converted InputStream into byte array in web layer itself and wrap this byte array in java DTO and transfer this DTO to business layer where I perform database operation and it worked fine.

Thanks a lot.

-Aniket
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear you have solved the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!