I'm building an ATM simulator, with the Deposit, Draw, and Extract features functional. But I'm not getting the balance.
I have the emitirSaldo()
method that should receive the value calculated by the query. Here is the code:
public Extrato emitirSaldo(Extrato mod) {
conex.conecta();
conex.executeSQL
("SELECT (SELECT SUM(valor) FROM extrato where Transacao = 'Deposito') "
+ "- (SELECT SUM(valor) FROM extrato where Transacao = 'Saque')");
try {
conex.resultset.first();
mod.setSaldo(conex.resultset.getString("Valor"));
JOptionPane.showMessageDialog(null, "Saldo recebido.");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Erro ao apresentar o saldo./nErro: " + ex);
}
conex.desconecta();
return mod;
}
This method is called inside the view button:
private void btnVisualizarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
model = control.emitirSaldo(model);
lblSaldo.setText(model.getSaldo());
}
When I run the program, the error is displayed:
"java.sql.SQLException: Column 'Value' not found."
But in the database there is the Value column:
HowcanIcalculatethebalanceanddisplayitinFormSaldobyclickingthePreviewbutton?