Olha eu to com o Erro ja depurei e vi q o problema é no meu DAO
public void inserir(PacienteBean paciente) throws SQLException {
this.setConnection("sal");
this.open();
String sql = "INSERT INTO paciente "
+ "(idPaciente,nome,cpf,rg,nomeMae,cartaoSus,telefone,celular,rua,"
+ "complemento,numero,bairro,cidade,estado,sexo,data) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
System.out.println(sql+" - "+this.getCodigo());
this.prepare(sql);
int id = getCodigo();
this.setInt(1, id);
this.setString(2, paciente.getNome());
this.setString(3, paciente.getCpfCnpj());
this.setString(4, paciente.getRgie());
this.setString(5, paciente.getNomeMae());
this.setString(6, paciente.getCartaoSus());
this.setString(7, paciente.getTelefone());
this.setString(8, paciente.getCelular());
this.setString(9, paciente.getRua());
this.setString(10, paciente.getComplemento());
this.setInt(11, paciente.getNumero());
this.setString(12, paciente.getBairro());
this.setString(13, paciente.getCidade());
this.setString(14, paciente.getEstado());
this.setString(15, paciente.getSexo());
this.setDate(16, paciente.getData());
this.execute();
this.close();
}
o Erro acontece na Linha on gera o id
o metodo q incrementa o Codigo é o getCodigo q eh esss
public int getCodigo() throws SQLException {
//this.setConnection("sal");
//this.open();
String SQLi = "SELECT HIGH_PRIORITY IFNULL(MAX(idPaciente),0)+1 AS ID FROM paciente";
this.prepare(SQLi);
this.executeQuery();
this.getRS().first();
int novoId = this.getRS().getInt("ID");
//this.close();
return novoId;
}
e o metodo de inserir da tela é esse
private void salvar() {
if (this.verificarCampos()) {
return;
}
try {
if (this.isInserir()) {
PacienteBean paciente = new PacienteBean();
paciente.setNome(this.txNome.getText().trim().toUpperCase());
paciente.setBairro(this.txBairro.getText().trim().toUpperCase());
paciente.setCartaoSus(this.txNumeroSUS.getText().trim().toUpperCase());
paciente.setCelular(this.txCelular.getText().trim().toUpperCase());
paciente.setData(dtDataNascimento.getDate());
paciente.setComplemento(this.txComplemento.getText().trim().toUpperCase());
paciente.setCpfCnpj(this.txCpf.getText().trim().toUpperCase());
paciente.setNumero(Integer.parseInt(this.txNumero.getText()));
this.pacienteDao.inserir(pacienteBean);
Msg.informacao(this, "Salvo com sucesso.");
this.telaBusca.atualizarTabela();
this.cancelar();
} else {
PacienteBean paciente = new PacienteBean();
paciente.setIdPaciente(this.idPaciente);
paciente.setNome(this.txNome.getText().trim().toUpperCase());
this.pacienteDao.alterar(paciente);
Msg.informacao(this, "Alterado Com Sucesso.");
this.telaBusca.atualizarTabela();
this.cancelar();
}
} catch (SQLException ex) {
ex.printStackTrace();
Msg.erro(this, "Erro ao salvar. \n" + ex.getMessage());
}
}
this.pacienteDao.inserir(pacienteBean);
é a hora que ele manda pro DAO e o mesmo tem q gerar o codigo usando o metodo...
Me ajudem aew ... ja faz tempo que to tentando achar o erro...
obrigado desde Já