O erro acontece quando eu mando pesquisar no banco e n existe o dado
23/12/2010 10:52:46 tela.Tela jToggleButtonConsultaPelaMatriculaActionPerformed
GRAVE: null
java.sql.SQLException: Illegal operation on empty result set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:841)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5656)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5576)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5616)
at dao.FuncionarioDAO.getSelecionaMatricula(FuncionarioDAO.java:102)
at tela.Tela.jToggleButtonConsultaPelaMatriculaActionPerformed(Tela.java:658)
at tela.Tela.access$1000(Tela.java:13)
at tela.Tela$11.actionPerformed(Tela.java:208)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:291)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
CONSTRUÍDO COM SUCESSO (tempo total: 15 segundos)
Os metodos relacionados são os seguintes...
private void jToggleButtonConsultaPelaMatriculaActionPerformed(java.awt.event.ActionEvent evt) {
jButtonAlterar.setVisible(true);
jButtonExcluir.setVisible(true);
if (jTMatricula.getText().matches("\d+")) {
String recebeSexoDoBanco;
funcionario = new Funcionario();
funcionarioDAO = new FuncionarioDAO();
try {
funcionario = funcionarioDAO.getSelecionaMatricula(Integer.parseInt(jTMatricula.getText()));
jFormattedTextFieldData.setText("");
jTBairro.setText(funcionario.getBairro());
jTCEP.setText(funcionario.getCep());
jTCPF.setText(funcionario.getCpf());
jTCel.setText(Integer.toString(funcionario.getCel()));
jTCidade.setText(funcionario.getCidade());
jTMatricula.setText(Integer.toString(funcionario.getMatricula()));
jTNome.setText(funcionario.getNome());
jTNomeMae.setText(funcionario.getNomeMae());
jTNomePai.setText(funcionario.getNomePai());
jTNumero.setText(Integer.toString(funcionario.getnCasa()));
jTRua.setText(funcionario.getRua());
jTTel.setText(Integer.toString(funcionario.getTel()));
Valida v = new Valida();
jFormattedTextFieldData.setText(v.bdParaString(funcionario.getDataNasc()));
if (funcionario.getSexo().equalsIgnoreCase("m")) {
jRadioButtonMasculino.setSelected(rootPaneCheckingEnabled);
} else if (funcionario.getSexo().equalsIgnoreCase("f")) {
jRadioButtonFeminino.setSelected(rootPaneCheckingEnabled);
}else{
buttonGroupSexo.clearSelection();
}
if (funcionario.getEstadoCivil().equalsIgnoreCase("casado")) {
jRadioButtonCasado.setSelected(rootPaneCheckingEnabled);
} else if (funcionario.getEstadoCivil().equalsIgnoreCase("divorciado")) {
jRadioButtonDivorciado.setSelected(rootPaneCheckingEnabled);
} else if (funcionario.getEstadoCivil().equalsIgnoreCase("solteiro")) {
jRadioButtonSolteiro.setSelected(rootPaneCheckingEnabled);
} else if (funcionario.getEstadoCivil().equalsIgnoreCase("viuvo")) {
jRadioButtonViuvo.setSelected(rootPaneCheckingEnabled);
} else if (funcionario.getEstadoCivil().equalsIgnoreCase("outros")) {
jRadioButtonOutros.setSelected(rootPaneCheckingEnabled);
}else{
bttgroupEstadoCivil.clearSelection();
}
if (funcionario.getUf().equalsIgnoreCase("SP")) {
jComboBoxUF.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"SP", "RJ", "MG", "ES", "RS", "AM"}));
} else if (funcionario.getUf().equalsIgnoreCase("ES")) {
jComboBoxUF.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"ES", "SP", "RJ", "MG", "RS", "AM"}));
} else if (funcionario.getUf().equalsIgnoreCase("MG")) {
jComboBoxUF.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"MG", "ES", "SP", "RJ", "RS", "AM"}));
} else if (funcionario.getUf().equalsIgnoreCase("RS")) {
jComboBoxUF.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"RS", "MG", "ES", "SP", "RJ", "AM"}));
} else if (funcionario.getUf().equalsIgnoreCase("AM")) {
jComboBoxUF.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"AM", "RS", "MG", "ES", "SP", "RJ",}));
} else if (funcionario.getUf().equalsIgnoreCase("RJ")) {
jComboBoxUF.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"RJ", "AM", "RS", "MG", "ES", "SP",}));
} else {
jComboBoxUF.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"", "RJ", "AM", "RS", "MG", "ES", "SP",}));
}
} catch (SQLException ex) {
Logger.getLogger(Tela.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Funcionario getSelecionaMatricula(int matricula) throws SQLException {
Funcionario funcionario = new Funcionario();
PreparedStatement stmt = this.connection.prepareStatement("select * from funcionario where matricula=?");
stmt.setInt(1, matricula);
ResultSet rs = stmt.executeQuery();
rs.next();
funcionario.setNome(rs.getString("nome"));
funcionario.setBairro(rs.getString("bairro"));
funcionario.setCel(rs.getInt("celular"));
funcionario.setCep(rs.getString("CEP"));
funcionario.setCidade(rs.getString("Cidade"));
funcionario.setCpf(rs.getString("cpf"));
funcionario.setEstadoCivil(rs.getString("estadoCivil"));
funcionario.setMatricula(rs.getInt("matricula"));
funcionario.setNomeMae(rs.getString("nomeMae"));
funcionario.setNomePai(rs.getString("nomePai"));
funcionario.setRua(rs.getString("rua"));
funcionario.setSexo(rs.getString("sexo"));
funcionario.setTel(rs.getInt("telefone"));
funcionario.setUf(rs.getString("uf"));
funcionario.setnCasa(rs.getInt("numeroCasa"));
funcionario.setDataNasc(rs.getDate("dataNascimento"));
rs.close();
stmt.close();
return funcionario;
}