I have two inventory and product tables, in product I have some data and in other inventory, they are linked by the product number. In my code I have two objects that have the columns of each table as attributes. Until there nothing new.
Generally, when I consult a table of a single type of objects, I save the results in an ArrayList of the object type (product, inventory, etc). The issue is that I will make a query that shows me data of both tables with a join, but I do not know how to save the results. In summary would be a multidimensional list that is the first time I perform.
Someone who takes pity on me !!!! PS I think I have no problems with the query because it pulls .. My Product object
public class Producto implements Serializable {
private int Num_Producto;
private String NombreProd;
private String Clasificacion;
private float Precio_Venta;
private float Precio_Compra;
My Inventory Object
public class Inventario implements Serializable {
private int Num_Inventario;
private int Producto_Num;
private int Cantidad;
private int EmpleadoSrv;
private String FechaCad;
private String Lote;
My method attempt
public static ArrayList ***no se como va ****ConsultarProductobyInventario() {
PreparedStatement st = null;
try {
String SQL = "SELECT producto.NombreProd, producto.Clasificacion, producto.Precio_Venta, inventario.Cantidad, inventario.Lote FROM producto join inventario on inventario.Producto_Num = producto.Num_Producto;";
st= conexion().prepareStatement(SQL);
ResultSet res = st.executeQuery();
ArrayList<Producto> lista = new ArrayList<>();
Producto prod;
while(res.next()){ //aqui menos!!!!
prod=new Producto();
prod.setNum_Producto(res.getInt("num_producto"));
prod.setNombreProd(res.getString("nombreprod"));
prod.setClasificacion(res.getString("clasificacion"));
prod.setPrecio_Venta(res.getInt("precio_venta"));
prod.setPrecio_Compra(res.getInt("precio_compra"));
lista.add(prod);
}
//st.close();
return lista;
} catch (SQLException ex){
Logger.getLogger(EmpresaDAO.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}