wood burning stoves 2.0*
The moose likes Java in General and the fly likes Error while updating image data in database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Error while updating image data in database" Watch "Error while updating image data in database" New topic

Error while updating image data in database

Rudra Nath

Joined: May 12, 2012
Posts: 9
I have table where datatype of a column is CLOB.
String query = "update tablename set image=?'";
PreparedStatement st1=conn.prepareStatement(query);
st1.setBlob(1,new DataInputStream(myImg));
int retVal = st1.executeUpdate();

I am getting following error:
root cause

javax.servlet.ServletException: java.lang.AbstractMethodError: oracle.jdbc.driver.T4CPreparedStatement.setBlob(ILjava/io/InputStream;)V

Thanks for your help!
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

We'll need a little more information than that.

Also, I noticed three quotes ''' in your prepared statement. Is that by design or a typo error?

Rudra Nath

Joined: May 12, 2012
Posts: 9
three quote is typo.
I was selecting an image from a JSP file like this:
<script language="javascript">
function submitPage(content){

var myImg=document.getElementById("myImg");

<form enctype="multipart/form-data" name="myForm" method="post">
String loginId = request.getParameter("loginid");

File dir = new File("C:/Tomcat/apache-tomcat-6.0.32/webapps/BeyondSmile/images/tmp/"+loginId);
File[] children = dir.listFiles();
if (children == null) {
System.out.println("tmp is blank");
// Either dir does not exist or is not a directory
} else {
StringBuffer filename =null;
StringBuffer filenameAbs =null;
InputStream is = null;
for (int i=0; i<children.length; i++) {
filename =new StringBuffer();
filenameAbs =new StringBuffer();
is= new FileInputStream(filenameAbs.toString());
<input type="image" id="myImg" src="<%= filename.toString()%>" height="100" width="100" onclick="javascript:submitPage('myImg=<%= is %>');">
<input type="hidden" name="myImg" value='<%=is %>'>

Here I am seding image as hidden parameter.
In next JSP page, I am retriving it like this:
InputStream myImg = (InputStream)request.getSession().getAttribute("myImg");
and it is not null.
then I am trying to update it in database (Oracle 10g)
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

setBlob(int, InputStream) was only added in Java 6. Your JDBC driver probably is out of date. Check if there's an updated version.

If there isn't, you have a few choices. One is to use setBinaryStream(int, InputStream, int), but you have to know the number of bytes that will be stored. If you don't know that, copy the contents of the InputStream to a ByteArrayOutputStream, get its data (toByteArray()) and use that with setBytes(int, byte[]).

How To Ask Questions How To Answer Questions
I agree. Here's the link: http://aspose.com/file-tools
subject: Error while updating image data in database
Similar Threads
java.sql.SQLException: not all varaibles bound
insert query for mysql convert() using the tomcat
Inserting Blob data into Oracle DB through JDBC
missing return statement error
not redirecting to main page