Erro ao inserir dados no SQL Server

2 respostas
F

Galera eu to tentando fazer uma inserção no banco mas os campos que eu vou pegar do bean vao para o banco como o null, eu ja debuguei e aparece o bean preenchido???
Alguma ideia??

public void inserirDados(Collection list) {
				
		Sindical_Bean beanInterno= new Sindical_Bean();
		Iterator it= list.iterator();
		
		
		String sql=("Insert Into tblBaixaSindical (idPagamento,cnpj" +
				",valorJuro,valorMulta,valorDaGuia,exercicio,tipo,meio" +
				",banco,entidadeSindical,usuario,capitalSocial,dataVencimento" +
				",dataPagamento,dataBaixa) values(000,"+beanInterno.getCnpj()+",0,0,"
				+beanInterno.getValorContribuicao()+","+beanInterno.getExercicio()+
				",'guia','normal','bb','Fecomercio',63,0,"+beanInterno.getDataVencimento()+","
				+beanInterno.getDataPagamento()+","+beanInterno.getDataBaixa()+");");
		//conexaoSQLServer = con.conectarBancoSqlServer();
		
		
		try {
			stmt =conexaoSQLServer.createStatement();
			//rs= stmt.executeQuery(sql);
			while(it.hasNext()){
				beanInterno=(Sindical_Bean) it.next();
				System.out.println(beanInterno.getCnpj());
				
				rs= stmt.executeQuery(sql);
			}
			
			} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
	
	}

Falow!!!!

2 Respostas

T

O melhor é usar PreparedStatement e "?", mas como você quer saber porque é que está dando errado, veja o código a seguir:

public void inserirDados(Collection list) {
				
		Sindical_Bean beanInterno= new Sindical_Bean();
		Iterator it= list.iterator();
		
		
		String sql;
		//conexaoSQLServer = con.conectarBancoSqlServer();
		
		
		try {
			stmt =conexaoSQLServer.createStatement();
			//rs= stmt.executeQuery(sql);
			while(it.hasNext()){
				beanInterno=(Sindical_Bean) it.next();
				System.out.println(beanInterno.getCnpj());
sql =("Insert Into tblBaixaSindical (idPagamento,cnpj" +
				",valorJuro,valorMulta,valorDaGuia,exercicio,tipo,meio" +
				",banco,entidadeSindical,usuario,capitalSocial,dataVencimento" +
				",dataPagamento,dataBaixa) values(000,"+beanInterno.getCnpj()+",0,0,"
				+beanInterno.getValorContribuicao()+","+beanInterno.getExercicio()+
				",'guia','normal','bb','Fecomercio',63,0,"+beanInterno.getDataVencimento()+","
				+beanInterno.getDataPagamento()+","+beanInterno.getDataBaixa()+");");				
				rs= stmt.executeQuery(sql);
			}
			
			} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
	
	}
F

Valeu agora deu certo thingol,
mas se eu tinha declarado a string com o codigo sql antes nao deveria funcionar tambem???
E mesmo assim desse jeito ele nao inseriu a lista toda so inseriu um registro???

valeu!!!

Criado 17 de maio de 2006
Ultima resposta 17 de mai. de 2006
Respostas 2
Participantes 2