private void jButtonBuscarActionPerformed(java.awt.event.ActionEvent evt) {
String parametro = jTextFieldBuscar.getText();
if(jRadioButtonAluno.isSelected()){
alunoVo.setNome(parametro);
alunoVo = alunoDao.localizarAluno(alunoVo);
jLabelCodigo.setText(("codigo: "+alunoVo.getCod_aluno()));
jLabelNome.setText("nome: "+alunoVo.getNome());
jLabelEmail.setText("email: "+alunoVo.getEmail());
jLabelTelefone.setText("telefone: "+alunoVo.getTelefone());
jLabelIdade.setText("idade: "+alunoVo.getIdade());
//modelo.addRow(vetorTupla);
//modelo.setValueAt(jTable1, WIDTH, WIDTH);
}
}
public AlunoVo localizarAluno(AlunoVo aluno){
String sql = "SELECT cod_aluno, nome, telefone, email, idade FROM aluno WHERE nome = '"+aluno.getNome()+"'";
try{
PreparedStatement pst = conexao.getConection().prepareStatement(sql);
ResultSet rs = pst.executeQuery(sql);
rs.next();
aluno.setCod_aluno(Integer.parseInt(rs.getString("cod_aluno")));
aluno.setNome(rs.getString("nome"));
aluno.setTelefone(rs.getString("telefone"));
aluno.setEmail(rs.getString("email"));
aluno.setIdade(Integer.parseInt(rs.getString("idade")));
}catch(SQLException ex){
ex.printStackTrace();
}
return aluno;
}
O erro apresentado é o seguinte:
[list]run:
org.postgresql.util.PSQLException: Não pode utilizar métodos de consulta que pegam uma consulta de um comando preparado.
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:249)
at lista10.DAO.AlunoDao.localizarAluno(AlunoDao.java:64)
at lista10.VIEW.TelaPrincipal.jButtonBuscarActionPerformed(TelaPrincipal.java:250)
at lista10.VIEW.TelaPrincipal.access$000(TelaPrincipal.java:16)
at lista10.VIEW.TelaPrincipal$1.actionPerformed(TelaPrincipal.java:104)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
at java.awt.EventQueue.access$000(EventQueue.java:102)
at java.awt.EventQueue$3.run(EventQueue.java:662)
at java.awt.EventQueue$3.run(EventQueue.java:660)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:676)
at java.awt.EventQueue$4.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
CONSTRUÍDO COM SUCESSO (tempo total: 19 segundos)
[/list]
vlw