ByteArrayOutputStreamとして表されるPDFファイルをテーブルのBlobSQLフィールドに保存する必要があります。コードは次のとおりです。
public boolean savePDF(int version, ByteArrayOutputStream baos) throws Exception{
boolean completed = false;
ConnectionManager conn = new ConnectionManager();
try {
PreparedStatement statement = conn.getConnection().prepareStatement(INSERT_PDF);
statement.setLong(1, version);
statement.setBlob(2, (Blob)baos);
statement.execute();
conn.commit();
completed = true;
} catch (SQLException e) {
conn.rollbackQuietly();
e.printStackTrace();
throw e;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally{
conn.close();
}
return completed;
}
しかし、java.lang.ClassCastExceptionが発生します。
java.io.ByteArrayOutputStream cannot be cast to java.sql.Blob
どうすればそれを管理できますか?ありがとう