programa sem erros, mas retorna o valor errado, sempre retorna 0.0
oque eu faço pra na textfield aparecer o valor correto, que é o resultado do banco.
valeu.
public double calcula(Cheque x1) throws SQLException {
String sql = "select sum(valor) as Total from cheque where datapag between ? and ?";
PreparedStatement stmt = this.conexao.prepareStatement(sql);
stmt.setString(1, x1.getData1());
stmt.setString(2, x1.getData2());
ResultSet rs = stmt.executeQuery();
double valor1=0;
while (rs.next()) {
valor1 = rs.getDouble("Total");
}
rs.close();
stmt.close();
return valor1;
}
public class jTSoma extends javax.swing.JFrame {
private double valor1;
public void calcular() {
try {
Cheque x1 = new Cheque();
x1.setDatapag(jTData1.getText());
x1.setDatapag2(jTData2.getText());
ChequeDao dao = new ChequeDao();
valor1 = dao.calcula(x1);
} catch (SQLException ex) {
Logger.getLogger(jTCheque.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jBSomaeListaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
calcular();
jTTotal.setText(""+valor1);
}