Duvida para inserir "sequences" no meu JDBC

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.

Olá
Para colocar seu código bonitinho no GUJ, é só usar [code][/code]
dai ele fica certinho…

Não sei ao certo, mas como vc falou que esta NULL, vc tentou debugar
para ver se seu objeto esta populado?
Tenta fazer outro teste tanta colocar valores fixos para só ver se esta
inserindo!!

PS.: Poderia colocar o erro que ele esta ocorrendo no console
a exception…

Espero ter ajudado
flwssss

Depois de 61 posts?


Já checou o número colunas, o número de parâmetros que está passando, estou vendo uma diferença entre os dois.

sq_pagto_titulos_off.nextval não deveria estar com os VALUES, e sim nos ps.setXXX

São 12 colunas e 12 parâmetros. Na verdade eu nem faço idéia que deveria colocar sequence no PS…estou sabendo por vc agora. Mas enfim…não resolve. Debuguei e ele entra como NULL no parametro ID_LANCAMENTO.
Não conheço bem Bancos de Dados…mas tenho me esforçado pra aprender.
Valeu pela ajuda.

Vejo apenas 11 colunas no SQL.

Após muitos atropelos consegui. Ficou assim gente:

[code]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, ID_LANCAMENTO ) " );

		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.setDate(3, new java.sql.Date (filtroDataPagamento.getTime()) );
				ps.setLong(4, idVend.longValue() );
				if(idOper != null){
					ps.setInt(5, idOper.intValue());
				} else {
					ps.setNull(5, Types.INTEGER);
				}
			
				ps.setLong(6, nrPDV.longValue() );
				ps.setLong(7, idCliente.longValue() );
				ps.setLong(8, idConta.longValue() );
				ps.setLong(9, idEmpDiv.longValue() );
				ps.setLong(10, filtroNrDocumento.longValue() );
				ps.setDouble(11, filtroVlPagamento.doubleValue() );
				
				
				ps.executeUpdate();
				[/code]

Valeu a ajuda…eu tinha que deixar sem declaração de variáveis.

Abraço.