-1
I’m in doubt on a role of how to do a comic search. It’s going to catch. Can anyone tell why? And how to solve?
That is the function
public void consultar(){
String sql ="select * from tbaluno where idaluno=?";
try {
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, textid.getText());
rs = stmt.executeQuery();
if(rs.next())
System.out.println(textid);
if(rs.next()){
Usuario usuario = new Usuario();
usuario.setNomealuno(rs.getString("nomealuno"));
txtnome.setText(rs.getString(2));
}else{
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
The message that appears when I put an existing id in the database:
java.lang.NullPointerException
EDIT-> Mysql Table, Contains:
ID | Name
1 | Vinicius
I wanted when I put the id 1, to show in the field the name "Vinicius". The change I made in the function consult above, was just remove one if and exchange the other by while.
Do not know, because there is no way to test, all these variables inside Try may be causing the error, provide a [mcve] so that it is possible to verify the origin of the problem.
– user28595