Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error while updating image data in database

 
Rudra Nath
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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[]).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic