5

I am creating webapplication using JSF2.0 where in mysql, I am storing images using datatype as MEDIUMBLOB.

To insert values, I am using PreparedStatement as shown below.

PreparedStatement psmnt = con.prepareStatement("INSERT INTO sketchesSG002003 (userid, imageTitle, imageData, drawingComments) VALUES (?,?,?,?)");
psmnt.setLong(1, personalInfoId);
psmnt.setString(2, sketchesSG002003Title);

try {
    String fileName = FilenameUtils.getName(sketchesSG002003ImageUpload.getName());
    File image = new File(fileName);
    InputStream fis = sketchesSG002003ImageUpload.getInputStream();
    psmnt.setBinaryStream(3, fis, (int) sketchesSG002003ImageUpload.getSize());
} catch (Exception e) {
    psmnt.setBinaryStream(3, null);
}
psmnt.setString(4, sketchesSG002003Comments);
i = psmnt.executeUpdate();

However I am getting error as

java.lang.AbstractMethodError: com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;)V

Some part of Stacktrace is

 javax.faces.el.EvaluationException: java.lang.AbstractMethodError: com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;)V
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)

I believe above error is for statement psmnt.setBinaryStream(3, null);

My question is how can I set binary data as Null or Nothing?

2
  • This problem is not JSF related. Commented Jul 16, 2012 at 0:56
  • I know, however as I was using that technology, I thought to include it... nothing else... Commented Jul 16, 2012 at 1:08

1 Answer 1

7

What is going wrong these days? I get solution after I ask question :(

psmnt.setNull(3, java.sql.Types.BLOB); did the trick.

Sign up to request clarification or add additional context in comments.

1 Comment

is there any difference between LongBlob and normal blob in this case?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.