【问题标题】:setting blob to null using PreparedStatement使用 PreparedStatement 将 blob 设置为 null
【发布时间】:2012-07-14 20:45:10
【问题描述】:

我正在使用 JSF2.0 创建 Web 应用程序,而在 mysql 中,我使用数据类型为 MEDIUMBLOB 存储图像。

要插入值,我使用的是 PreparedStatement,如下所示。

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 的某些部分是

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

我的问题是如何将二进制数据设置为 Null 或 Nothing?

【问题讨论】:

  • 这个问题与 JSF 无关。
  • 我知道,但是当我使用该技术时,我想把它包括在内......没有别的......

标签: java mysql blob binarystream


【解决方案1】:

这几天出了什么问题?我提出问题后得到解决方案:(

psmnt.setNull(3, java.sql.Types.BLOB); 成功了。

【讨论】:

  • 这种情况下LongBlob和普通blob有区别吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-23
  • 2011-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多