I have the following code that is part of a class that handles the events of a frame :
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()== NuevoEstudiante.btnGuardar){
String nombre= nuevoEstudiante.txtNombre.getText();
String materia= nuevoEstudiante.txtMatricula.getText();
String nota= nuevoEstudiante.txtNota.getText();
String datos= DAO.guardar(new Estudiante(nombre, materia, Integer.parseInt(nota)));
if(datos!= null){
JOptionPane.showMessageDialog(null, datos);
}else{
JOptionPane.showMessageDialog(null, "Registro Erroneo.");
}
}
}
When I try to save the parameters received in the data variable
String datos= DAO.guardar(new Estudiante(nombre, materia, Integer.parseInt(nota)));
Netbeans gives me an error saying: incompatible types: void can not be converted to String , can you tell me how I can solve this error or if I have to redo my code in another way, I'll thank you for an example.
The save method used is part of a DAO as follows:
public void guardar(Estudiante e) {
Connection con = null;
PreparedStatement pstmnt = null;
try {
con = dbcon.conectar();
String sql = "INSERT INTO notas(nombre, matricula, nota) "
+ "VALUES(?, ?, ?)";
pstmnt = con.prepareStatement(sql);
pstmnt.setString(1, e.getNombre());
pstmnt.setString(2, e.getMatricula());
pstmnt.setInt(3, e.getNota());
pstmnt.execute();
} catch (SQLException ex) {
//System.out.println("Error al conectar a la BD");
JOptionPane.showMessageDialog(null, "Error al conectar a la BD");
}finally {
dbcon.desconectar(con);
}
}