使用PreparedStatement将blob设置为null [英] setting blob to null using PreparedStatement
本文介绍了使用PreparedStatement将blob设置为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用JSF2.0创建Web应用程序,其中在mysql中,我使用数据类型为MEDIUMBLOB
来存储图像.
I am creating webapplication using JSF2.0 where in mysql, I am storing images using datatype as MEDIUMBLOB
.
要插入值,我正在使用PreparedStatement,如下所示.
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();
但是我遇到错误
java.lang.AbstractMethodError: com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;)V
Stacktrace的某些部分是
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)
我认为上述错误是针对语句psmnt.setBinaryStream(3, null);
I believe above error is for statement psmnt.setBinaryStream(3, null);
我的问题是如何将二进制数据设置为Null或Nothing?
推荐答案
这几天出了什么问题?我问了问题后就得到了解决方法:(
What is going wrong these days? I get solution after I ask question :(
psmnt.setNull(3, java.sql.Types.BLOB);
做到了.
这篇关于使用PreparedStatement将blob设置为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文