SQL query to get fields in Java

0

What exactly would an SQL query be according to the following method?

The problem is that with the three tables I can not get it out correctly. The only thing that would have to be modified would be the consultation.

-show OrderData (int OrderNumber) . This method will consult the database and show the last order as a parameter, the products that it includes (code and name) and the quantity requested of each of them.

Activity tables:

Code:

public static void mostrarDatosPedido(int numeroPedido)
throws ClassNotFoundException, SQLException {

    ConectarSingleton conexion = new ConectarSingleton();
    Connection con = conexion.getConexion(); //añadir excep.

    ResultSet rs = GestionClassic.consultar("select * from pedidos where numeroPedido='"+numeroPedido+"'");
    while(rs.next()) {
        System.out.println(rs.getInt(1)+"\t"+rs.getDate(2)+"\t"+rs.getDate(3)+"\t"
                +rs.getDate(4)+"\t"+rs.getString(5)+"\t"+rs.getString(6)+"\t"+rs.getInt(7)+"\t"); 
    }
}
    
asked by user09b 04.09.2018 в 23:07
source

1 answer

1

In the query you have to put after the select the fields that you want to see, that is, Productcode, Productname and quantity Order making a join with the detailed tables and products. In this case you do not need to use the requested tables since in the other two you have all the necessary information.

The result would be something like this:

"SELECT detallespedidos.codigoProducto, productos.nombreProducto, detallesPedidos.cantidadPedida
FROM detallespedidos INNER JOIN productos ON(detallespedidos.codigoProducto = productos.codigoProducto)
WHERE detallespedidos.numeroPedido = " + numeroPedido + ";"
    
answered by 05.09.2018 / 00:47
source