first commit

parents
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
public class App {
public static void main(String args[]) {
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = 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);
}
System.out.println("Opened database successfully");
try {
Statement stmt = c.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");
System.out.println("NOMBRE = " + nombre);
System.out.println("APELLIDO = " + apellido);
System.out.println("CANTIDAD FACTURA = " + cantidad);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
}
try {
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("select b.nombre, count(moneda_id) Cantidad from factura a\n" +
"inner join moneda b\n" +
"on b.id=a.moneda_id\n" +
"group by b.nombre, a.moneda_id\n" +
"order by cantidad desc");
while (rs.next()) {
String nombre = rs.getString("nombre");
int cantidad = rs.getInt("Cantidad");
System.out.println("MONEDA = " + nombre);
System.out.println("CANTIDAD = " + cantidad);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
try {
Statement stmt = c.createStatement();
ResultSet rs = stmt
.executeQuery("select f.nombre, f.apellido, cast(sum(c.cantidad*d.precio) as integer) as Gasto\n" +
"from factura_detalle c\n" +
"inner join producto d \n" +
"\ton d.id=producto_id\n" +
"inner join factura e \n" +
"\ton c.id=e.id\n" +
"inner join Cliente f \n" +
"\ton f.id=e.cliente_id\n" +
"group by f.nombre, f.apellido\n" +
"order by Gasto desc;");
while (rs.next()) {
String nombre = rs.getString("nombre");
String apellido = rs.getString("apellido");
int cantidad = rs.getInt("Gasto");
System.out.println("NOMBRE = " + nombre);
System.out.println("APELLIDO = " + apellido);
System.out.println("MAYOR GASTO = " + cantidad);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
try {
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("select b.nombre, count(proveedor_id) Cantidad from producto a\n" +
"inner join proveedor b\n" +
"on b.id=a.proveedor_id\n" +
"group by b.nombre, a.proveedor_id\n" +
"order by cantidad desc;");
while (rs.next()) {
String nombre = rs.getString("nombre");
int cantidad = rs.getInt("Cantidad");
System.out.println("PROVEEDOR = " + nombre);
System.out.println("MAS VECES = " + cantidad);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
// ///////////////////////////////////////
try {
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery(
"select b.nombre, a.producto_id, sum(cantidad) as cantidad_Total from factura_detalle a\n" +
"inner join producto b\n" +
"on b.id=a.producto_id\n" +
"group by producto_id,b.nombre\n" +
"ORDER BY cantidad_Total desc limit 10;");
while (rs.next()) {
String nombre = rs.getString("nombre");
String id = rs.getString("producto_id");
int cantidad = rs.getInt("cantidad_Total");
System.out.println("NOMBRE = " + nombre);
System.out.println("ID = " + id);
System.out.println("CANTIDAD TOTAL = " + cantidad);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
try {
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery(
"select b.nombre, a.producto_id, sum(cantidad) as cantidad_Total from factura_detalle a\n" +
"inner join producto b\n" +
"on b.id=a.producto_id\n" +
"group by producto_id,b.nombre\n" +
"ORDER BY cantidad_Total asc limit 10;");
while (rs.next()) {
String nombre = rs.getString("nombre");
String id = rs.getString("producto_id");
int cantidad = rs.getInt("cantidad_Total");
System.out.println("NOMBRE = " + nombre);
System.out.println("ID = " + id);
System.out.println("CANTIDAD TOTAL = " + cantidad);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
try {
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery(
"select a.nombre, a.apellido, b.fecha_emision, d.nombre as Producto, c.cantidad, e.nombre as Tipo_factura from cliente a\n"
+
"inner join factura b on a.id=b.cliente_id\n" +
"inner join factura_detalle c on c.factura_id = b.id\n" +
"inner join producto d on d.id=c.producto_id\n" +
"inner join factura_tipo e on e.id=b.factura_tipo_id\n" +
"order by b.id");
while (rs.next()) {
String nombre = rs.getString("nombre");
String apellido = rs.getString("apellido");
String fecha = rs.getString("fecha_emision");
String producto = rs.getString("producto");
String cantidad = rs.getString("cantidad");
String factura = rs.getString("Tipo_factura");
System.out.println("NOMBRE = " + nombre);
System.out.println("APELLIDO = " + apellido);
System.out.println("FECHA FACTURA = " + fecha);
System.out.println("PRODUCTO = " + producto);
System.out.println("CANTIDAD = " + cantidad);
System.out.println("TIPO FACTURA = " + factura);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
try {
Statement stmt = c.createStatement();
ResultSet rs = stmt
.executeQuery("select e.nombre, f.nombre as Tipo_Factura, sum(cantidad*precio) as Monto \n" +
"from factura a\n" +
"inner join Cliente e on e.id=a.cliente_id\n" +
"inner join factura_detalle b on a.id=b.factura_id\n" +
"inner join producto c on c.id=b.producto_id\n" +
"inner join factura_tipo f on f.id=a.factura_tipo_id\n" +
"group by a.id, e.nombre, Tipo_Factura\n" +
"order by Monto desc");
while (rs.next()) {
String nombre = rs.getString("nombre");
String tipoFactura = rs.getString("Tipo_Factura");
String monto = rs.getString("Monto");
System.out.println("NOMBRE = " + nombre);
System.out.println("TIPO FACTURA = " + tipoFactura);
System.out.println("MONTO = " + monto);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
try {
Statement stmt = c.createStatement();
ResultSet rs = stmt
.executeQuery("select e.nombre, f.nombre as Tipo_Factura, sum(cantidad*precio)*0.1 as Monto \n" +
"from factura a\n" +
"inner join Cliente e on e.id=a.cliente_id\n" +
"inner join factura_detalle b on a.id=b.factura_id\n" +
"inner join producto c on c.id=b.producto_id\n" +
"inner join factura_tipo f on f.id=a.factura_tipo_id\n" +
"group by a.id, e.nombre, Tipo_Factura\n" +
"order by Monto desc");
while (rs.next()) {
String nombre = rs.getString("nombre");
String tipoFactura = rs.getString("Tipo_Factura");
String monto = rs.getString("Monto");
System.out.println("NOMBRE = " + nombre);
System.out.println("TIPO FACTURA = " + tipoFactura);
System.out.println("Monto = " + monto);
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment