Home » Developer & Programmer » JDeveloper, Java & XML » setBlob and classCastException
setBlob and classCastException [message #91286] Tue, 02 July 2002 13:00 Go to next message
Sandro
Messages: 6
Registered: March 2002
Junior Member
Hi,

Can somebody help me to make my code work !? I don't found any place that shows an easy solution to write an java.sql.Blob to Oracle database.

I'm trying the code:
...
Connection con = ds.getConnection();
PreparedStatement pst = con.prepareStatement("insert into teste (id, thumbnail) values (?, ?)");
pst.setInt(1, Integer.parseInt(strID));
pst.setBlob(2, blob);
pst.executeUpdate();
...

Where blob is an object from inner class br.com.spectrum.MultipartRequest$FileBlob that implements the interface java.sql.Blob. strID is some parseable integer.

When I compile and run the code, I obtain the following exception stack trace:

java.lang.ClassCastException: br.com.spectrum.MultipartRequest$FileBlob
at oracle.jdbc.driver.OraclePreparedStatement.setBlob(OraclePreparedStatement.java:1819)
at com.evermind.sql.FilterPreparedStatement.setBlob(FilterPreparedStatement.java:437)
at com.evermind.sql.FilterPreparedStatement.setBlob(FilterPreparedStatement.java:437)
at com.evermind.sql.FilterPreparedStatement.setBlob(FilterPreparedStatement.java:437)
at com.evermind.sql.FilterPreparedStatement.setBlob(FilterPreparedStatement.java:437)
at teste.ThumbServlet.uploadFile(ThumbServlet.java:55)
at teste.ThumbServlet.service(ThumbServlet.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:336)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletReque
stDispatcher.java:684)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(Ser
vletRequestDispatcher.java:269)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpReques
tHandler.java:735)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.ja
va:243)
at com.evermind.util.ThreadPoolThread.run(ThreadPoolThread.java:64)

I'm making an servlet that receives an "multipart/form-data" request, and saves the uploaded file into some Oracle database, in the table teste.

Thanks.
Re: setBlob and classCastException [message #91291 is a reply to message #91286] Tue, 02 July 2002 23:44 Go to previous message
SKS
Messages: 26
Registered: February 2002
Junior Member
You can not insert directly.
First create an emty blob ,then you select the created record and update it with your blob data.
Previous Topic: RE: Oracle ORA-00911 Invalid Character
Next Topic: ORA-17413 Exceeding Key Size error
Goto Forum:
  


Current Time: Wed Aug 04 14:32:29 CDT 2021