1
I am trying to insert data into a table in the database, but returns error "null".
public void cadastrarChamadas() {
Chamadas1 cha= null;
String sql = "Insert into tb_chamadas(cha_cod , cha_nome, cha_defeito, cha_datainicio, cha_datafinal, cha_horainicio, cha_horafinal, cha_numerovisitas, cha_tipocontrato, cha_atividadesrealizadas) values(?,?,?,?,?,?,?,?,?,?)";
//Capturo o valor do campoTextField e coloco em valorTextField.
try {
int cont=0;
pst = con.prepareStatement(sql);
//seta os valores
pst.setInt(1,cha.getCod());
pst.setString(2,cha.getNome() );
pst.setString(3,cha.getDefeito());
pst.setString(4,cha.getDataInicio());
pst.setString(5, cha.getDataFinal());
pst.setInt(6, cha.getHoraInicio());
pst.setInt(7, cha.getHoraFinal());
pst.setInt(8, cont+1);
pst.setString(9, cha.getTipoServico());
pst.setString(10, cha.getAtividadesrealiadas());
//pst.setInt(14,Integer.parseInt(txtId.getText()));
pst.execute();
JOptionPane.showMessageDialog(null, "Dados das Chamadas Salvas:");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Erro na Inserção de dados:\n Erro:" + e.getMessage());
}
}
Now my database.
Error "null"? What do you mean? Nullpointerexception, right? If so, it’s because of this line:
Chamadas1 cha= null;
– igventurelli
I can not comment yet, so I will write as if it’s an answer, try to print the generated SQL and run it in the database to see if it works. You may have missed the data type only. I stand by.
– Renato Serra