Foxan
Maio 17, 2006, 2:48pm
#1
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??
[code]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();
}
}[/code]
Falow!!!
O melhor é usar PreparedStatement e “?”, mas como você quer saber porque é que está dando errado, veja o código a seguir:
[code]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();
}
}[/code]
Foxan
Maio 17, 2006, 3:04pm
#3
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!!!