シンプルなインターフェイス (jsf 1.2 およびリッチフェイス 3.3.2、Oracle 11g R1) を使用して、ユーザーが rich:fileUpload で画像を選択し、テーブルに保存できるようにしています。テストとして、次の表を作成しました。
CREATE TABLE TEST
(
MIME_TYPE VARCHAR2 (1000),
PHOTO BLOB,
STUDENT_ID NUMBER NOT NULL
)
画像を BLOB フィールドに保存するコード スニペットは次のとおりです。
//......From the uploadFile Listener
public void listener(UploadEvent event) throws Exception {
...
item = event.getUploadItem();
...
StudentPhotoDAO dao = new StudentPhotoDAO();
dao.storePhoto(item.getData(),item.getContentType(),studentId);
...
}
//......From the PhotoDAO ..........................
public void storePhoto(byte data[],String mimeType, Long studentId){
{
...
ByteArrayInputStream bis=new ByteArrayInputStream(data);
String query = "update TEST set PHOTO = ? ,MIME_TYPE = ? where STUDENT_ID=?";
pstmt = conn.prepareStatement(query);
pstmt.setAsciiStream(1,(InputStream)bis,data.length);
pstmt.setString(2,mimeType.toString());
pstmt.setLong(3,studentId);
pstmt.executeUpdate();
}
次のエラーが表示されます。
java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
コードのどこにエラーがありますか。
ありがとう。