Problemas ao tentar persistir uma imagem no campo ORDIMAGE do Oracle

1 resposta
anderson.bonavides

Pessoal, estou tentando persistir uma imagem em um campo OrdImage da oracle mas é gerado a seguinte mensagem:

java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement

No banco de dados tenho uma tabela chamada:

ID_DOCUMENTOIMAGEM que tem os seguintes campos:
ID_DOCUMENTOIMAGEM, FK_DOCUMENTO, ORDIMAGE

O erro acontece no meu método insertImage na linha 32

OraclePreparedStatement stmt2 = (OraclePreparedStatement) con.prepareStatement(rowSelectSQL);

public boolean insertImage(int fk_document, File imagem, Connection con) throws SQLException, IOException, ServletException {

		if (con == null) {
			con = Pilha.getConexao(); // Estabelce conexao
		}
		
		Statement stmt = null;
		InputStream streamImage = new FileInputStream(imagem);
		PreparedStatement ps = null;
		OrdImage imageProxy = null;
		OraclePreparedStatement opstmt = null;
		OracleResultSet rset = null;
		
		int resultado = 0;
		int id = 0;
		
		try{
			stmt = con.createStatement();
			id = retornaProximoIdDocumentoImagem(con);
			String rowInsertSQL = "insert into VEP_CNJ_TB_DOCUMENTO_IMAGEM (ID_DOCUMENTOIMAGEM, FK_DOCUMENTO, IMAGEM) values (" + id + ", " + fk_document + ", ordsys.ordimage.init ())";
			stmt.execute(rowInsertSQL);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			//alguma operação como fechar conexão...
		}
		
		try{
			con.setAutoCommit(false);
			String rowSelectSQL = "select IMAGEM from VEP_CNJ_TB_DOCUMENTO_IMAGEM where ID_DOCUMENTOIMAGEM = " + id + " for update";
			
			OraclePreparedStatement stmt2 = (OraclePreparedStatement) con.prepareStatement(rowSelectSQL);
			rset = (OracleResultSet) stmt2.executeQuery();
			
			rset.next();
			imageProxy = (OrdImage)rset.getORAData("IMAGEM", OrdImage.getORADataFactory());
			rset.close();
			imageProxy.loadDataFromInputStream(streamImage);
			imageProxy.setProperties();
		} catch (SQLException s) {
			s.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			rset.close();
		}
		
		try{
			String updateSQL = "update VEP_CNJ_TB_DOCUMENTO_IMAGEM set IMAGEM = ? where ID_DOCUMENTOIMAGEM = ?";
			opstmt = (OraclePreparedStatement)con.prepareStatement(updateSQL);
			opstmt.setORAData(1, imageProxy);
			opstmt.setInt(2, id);
		}finally{
			opstmt.execute();
			opstmt.close();
		}
		if (ps != null)
			ps.close();
		return resultado > 0;
	}

Alguem pode me ajudar?

Grato!

1 Resposta

T

Veja se isto funciona. Note que isto é um quebra-galho horrível:

org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement stmt = (org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement) con.prepareStatement(rowSelectSQL);


OraclePreparedStatement stmt2 = (OraclePreparedStatement) stmt.getDelegate() ;
Criado 16 de julho de 2009
Ultima resposta 16 de jul. de 2009
Respostas 1
Participantes 2