Olá gente;
Alguém pode me ajudar? Preciso inserir uma “sequence” em um determinado campo de uma tabela. O banco é ORACLE. Tentei apenas jogar a sequence na posição do campo mas ela me retorna NULL. Ou seja, dá erro.
Meu código ficou assim:
public void salvarDadosPagamentoFatura(
Integer idUnidadeNegocio,
Long filtroNrDocumento,Double filtroVlPagamento,Long idCliente, Long idVend,
Date filtroDataPagamento,Long idConta,Integer idOper,Long nrPDV,Long idEmpDiv, Long idEmp,Integer idLancamento) throws CommerceException {
Connection con = null;
PreparedStatement ps = null;
StringBuffer query = new StringBuffer();
query.append( "INSERT INTO PAGTO_TITULOS_OFF (ID_UNN,ID_EMP, DT_LANCAMENTO,ID_VEN,ID_OPER,NR_PDV, ID_CLI,ID_CONTA,ID_EMP_DIVIDA, ID_DIVIDA,VL_RECEB ) " );
query.append( "VALUES( ?,?,sq_pagto_titulos_off.nextval,?,?,?,?,?,?,?,?,? ) " );
try{
con = super.getConnection();
ps = con.prepareStatement( query.toString() );
ps.setInt( 1, idUnidadeNegocio.intValue() );
ps.setLong( 2, idEmp.longValue() );
ps.setInt(3,idLancamento.intValue());
ps.setDate( 4, new java.sql.Date (filtroDataPagamento.getTime()) );
ps.setLong(5, idVend.longValue() );
ps.setInt(6, idOper.intValue() );
ps.setLong(7, nrPDV.longValue() );
ps.setLong(8, idCliente.longValue() );
ps.setLong(9, idConta.longValue() );
ps.setLong(10, idEmpDiv.longValue() );
ps.setLong(11, filtroNrDocumento.longValue() );
ps.setDouble(12, filtroVlPagamento.doubleValue() );
ps.executeUpdate();
} catch (SQLException e) {
String mensagem = null;
if( e.getErrorCode() == 20001 ){
mensagem = CommerceException.getProcedureMessage( e.getMessage() );
}else {
mensagem = e.getMessage();
}
throw new CommerceException( mensagem, e.getErrorCode() );
} catch (Exception e) {
throw new CommerceException( e.getMessage() );
} finally {
super.closeObjetosConexao( con, ps );
}
}
}
PS: Ainda não aprendi a usar as tags de formatação do GUJ.
Valeu gente.