Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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
Author

Error while updating image data in database

Rudra Nath
Greenhorn

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
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)

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?

WP
Rudra Nath
Greenhorn

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");

document.myForm.action="/BeyondSmile/pages/home.jsp";
document.myForm.submit();
}
</script>
</head>
<body>
<form enctype="multipart/form-data" name="myForm" method="post">
<%
String loginId = request.getParameter("loginid");
System.out.println("newLeftPaneBody:loginId="+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();
filenameAbs.append("C:/Tomcat/apache-tomcat-6.0.32/webapps/BeyondSmile/images/tmp/"+loginId+"/"+children[i].getName());
filename.append("/BeyondSmile/images/tmp/"+loginId+"/"+children[i].getName());
is= new FileInputStream(filenameAbs.toString());
request.getSession().setAttribute("myImg",is);
%>
<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
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

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[]).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
not redirecting to main page
missing return statement error
java.sql.SQLException: not all varaibles bound
insert query for mysql convert() using the tomcat
Inserting Blob data into Oracle DB through JDBC