From 10224579f53b74a84c63e0a53c462ac3e91e15c9 Mon Sep 17 00:00:00 2001 From: Oscar Enrique Gonzalez Escurra Date: Thu, 22 Feb 2024 12:30:58 -0300 Subject: [PATCH] consulta SQL en jsp --- src/main/webapp/consultajsp.jsp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/main/webapp/consultajsp.jsp diff --git a/src/main/webapp/consultajsp.jsp b/src/main/webapp/consultajsp.jsp new file mode 100644 index 0000000..27c742b --- /dev/null +++ b/src/main/webapp/consultajsp.jsp @@ -0,0 +1,62 @@ +<%@ 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;"); + %> + + + + + + + <% + while (rs.next()) { + String nombre = rs.getString("nombre"); + String apellido = rs.getString("apellido"); + int cantidad = rs.getInt("Cantidad_factura"); + %> + + + + + + <% + } + rs.close(); + stmt.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + %> +
NombreApellidoCantidad de Facturas
<%= nombre %><%= apellido %><%= cantidad %>
+ + -- libgit2 0.26.0