Good day, I would like to know how to make a report using range of dates (start date, end date) in the GUI Method ... Any help?
- process
public class GestionReporteVentas implements ReporteVentasInterface{
@Override
public ArrayList<ReporteVentas> listado() {
ArrayList<ReporteVentas> lista = new ArrayList<ReporteVentas>();
ResultSet rs = null; // tipo de resultado
Connection con = null;
PreparedStatement pst = null;
try {
con = MySQLConexion.getConexion();
String sql = "{CALL usp_reporte1}"; // sentencia sql
pst = con.prepareStatement(sql);
// parámetros según la sentencia
rs = pst.executeQuery(); // tipo de ejecución
// Acciones adicionales en caso de consultas
while (rs.next()){
ReporteVentas rv = new ReporteVentas();
rv.setNumvta(rs.getString(1));
rv.setFechavta(rs.getString(2));
rv.setNomproducto(rs.getString(3));
rv.setNomvendedor(rs.getString(4));
rv.setMontoventa(rs.getDouble(5));
lista.add(rv);
}
} catch (Exception e) {
System.out.println("Error en la sentencia " + e.getMessage());
} finally {
try {
if (pst != null) pst.close();
if (con != null) con.close();
} catch (SQLException e) {
System.out.println("Error al cerrar ");
}
}
return lista;
}}
- IN THE GUI
void listarReporte(){
// llamar la gestion
GestionReporteVentas gr = new GestionReporteVentas();
ArrayList<ReporteVentas> lista = gr.listado();
if (lista == null){
txtListado.setText("LISTA VACIA");
}else {
txtListado.setText("NumVenta\tFechaV\tNomProducto\tNomVendedor\tMonto\n");
for (ReporteVentas rv : lista){
txtListado.append(rv.getNumvta() + "\t" + rv.getFechavta() + "\t" +
rv.getNomproducto() + "\t" + rv.getNomvendedor() + "\t" + rv.getMontoventa() +"\n");
}
} }