Inserção de arquivo

2 respostas
K

Pessoal,
O código abaixo esta funcionando apenas para arquivos menores que 4,00 KB, quando tento inserir um arquivo maior ocorre o seguinte problema na linha 22:
Exceção de E/S: Connection reset by peer: socket write error
Estou usando Struts 1.2 e banco Oracle
Se alguem puder ajudar obrigado.

public void insert(AttachmentVO att) throws OFDBException {

        PreparedStatement statement = null;
        try {

            int intValue = getNextAttachmentFileSeq(att.getProcId(), att
                    .getNumproc().intValue());

            statement = getConnection()
                    .prepareStatement(
                            "INSERT INTO GPNANEXO.TGP_ANEXO (GPCDPROCID, GPNUMPROC, GPFILESEQ, GPNMFILE, GPCDUSER, GPANEXO) VALUES (?,?,?,?,?,?)");

            statement.setString(1, att.getProcId());
            statement.setInt(2, att.getNumproc().intValue());
            statement.setInt(3, intValue);
            statement.setString(4, att.getNomeArquivo());
            statement.setString(5, att.getUsuario());

            statement.setBinaryStream(6, att.getAttachment(), att
                    .getAttachmentSize());

            statement.executeUpdate();

        } catch (Exception e) {
            throw new OFDBException(e);

        } finally {
            if (null != statement){
                try {
                    statement.close();
                } catch (SQLException e) {
                    throw new OFDBException(e);
                }
            }

        }

    }

2 Respostas

thiago.correa

Ou você:

1- aumente o tempo de timeout do banco!
2- leia todo o arquivo em memória e execute um insert em bacth http://java.sun.com/j2se/1.5.0/docs/api/java/sql/PreparedStatement.html#addBatch()

K

Cara
Tentei a segunda opção da seguinte forma:
e me foi retornada a seguinte exception:
OFDBException: operação não permitida: streams type cannot be used in batching

statement.setBinaryStream(6, att.getAttachment(), att
                    .getAttachmentSize());
            statement.addBatch();

            //statement.executeUpdate();
            statement.executeBatch();

Existe alguma outra forma? já que a primeira opção não posso fazer.
Desde já obrigado.

Criado 20 de março de 2009
Ultima resposta 20 de mar. de 2009
Respostas 2
Participantes 2