%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Consulta
<%
Connection connection = null;
try {
Class.forName("org.postgresql.Driver");
connection = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/bootcamp_market", "postgres", "postgres");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select a.nombre, apellido, count(b.cliente_id) Cantidad_factura from cliente a " +
"inner join factura b " +
"on a.id=b.cliente_id " +
"group by a.nombre, a.apellido " +
"order by Cantidad_factura desc;");
%>
Nombre |
Apellido |
Cantidad de Facturas |
<%
while (rs.next()) {
String nombre = rs.getString("nombre");
String apellido = rs.getString("apellido");
int cantidad = rs.getInt("Cantidad_factura");
%>
<%= nombre %> |
<%= apellido %> |
<%= cantidad %> |
<%
}
rs.close();
stmt.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
%>