Hi, I'm finishing a small application that stores, the total sales of each employee depending on the product sold. I am using a hashmap for this, since I have thought that this data structure is the most efficient for my project. The problem I have in that it shows me duplicate data and I can not find a way to remove these duplicates, attached source:
public static String totalizarIDEmpleadoArticulo() throws SQLException{
String sql = "SELECT * FROM ventas inner join articulos on ventas.idArt = articulos.idArt"
+ " ORDER BY ventas.idEmp, ventas.idArt";
rs = stmt.executeQuery(sql);
int empleado = 0;
int articulo;
String cadena = "";
double suma = 0;
rs.beforeFirst();
Object[] contenido = new String[50];
boolean correcto = rs.next();
while (correcto) {
suma = 0;
empleado = rs.getInt("idEmp");
articulo = rs.getInt("idArt");
while (correcto && empleado == rs.getInt("idEmp")) {
suma += rs.getDouble("ppu") * rs.getInt("unidades");
correcto = rs.next();
}
contenedor.put(empleado, suma);
contenido = contenedor.keySet().toArray();
for (int i = 0; i < contenido.length; i++) {
System.out.println("Empleado: " + "\t" + "total vendido:" + "\n" + "----------" + "\t" + "----------"
+ "\n" + empleado + "\t" + "\t" + suma);
}
}
return cadena;
}