5

私は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として設定するにはどうすればよいですか?

4

1 に答える 1

6

最近何が悪いのですか?質問した後、解決策が得られます:(

psmnt.setNull(3, java.sql.Types.BLOB);トリックをしました。

于 2012-07-16T00:48:53.140 に答える