Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
servlets
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jose Baez
servlets
Commits
8f3f5128
Commit
8f3f5128
authored
May 09, 2022
by
Josebaezx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
se crea consultas de prueba
parent
bb365c60
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
136 additions
and
54 deletions
+136
-54
.idea/encodings.xml
+0
-2
.idea/misc.xml
+2
-1
.idea/runConfigurations.xml
+11
-0
src/main/java/com/roshka/bootcamp/BD.java
+9
-49
src/main/java/com/roshka/bootcamp/ConsultaClienteFactura.java
+95
-0
src/main/webapp/index.jsp
+19
-2
target/classes/com/roshka/bootcamp/BD.class
+0
-0
target/classes/com/roshka/bootcamp/ConsultaClienteFactura.class
+0
-0
No files found.
.idea/encodings.xml
View file @
8f3f5128
...
@@ -2,6 +2,5 @@
...
@@ -2,6 +2,5 @@
<project
version=
"4"
>
<project
version=
"4"
>
<component
name=
"Encoding"
>
<component
name=
"Encoding"
>
<file
url=
"file://$PROJECT_DIR$/src/main/java"
charset=
"UTF-8"
/>
<file
url=
"file://$PROJECT_DIR$/src/main/java"
charset=
"UTF-8"
/>
<file
url=
"file://$PROJECT_DIR$/src/main/resources"
charset=
"UTF-8"
/>
</component>
</component>
</project>
</project>
\ No newline at end of file
.idea/misc.xml
View file @
8f3f5128
...
@@ -8,5 +8,5 @@
...
@@ -8,5 +8,5 @@
</list>
</list>
</option>
</option>
</component>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_8"
default=
"true"
project-jdk-name=
"
liberica-
1.8"
project-jdk-type=
"JavaSDK"
/>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_8"
default=
"true"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
/>
</project>
</project>
\ No newline at end of file
.idea/runConfigurations.xml
0 → 100644
View file @
8f3f5128
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"RunConfigurationProducerService"
>
<option
name=
"ignoredProducers"
>
<set>
<option
value=
"com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer"
/>
</set>
</option>
</component>
</project>
\ No newline at end of file
src/main/java/com/roshka/bootcamp/BD.java
View file @
8f3f5128
...
@@ -8,63 +8,23 @@ import jakarta.servlet.http.HttpServletResponse;
...
@@ -8,63 +8,23 @@ import jakarta.servlet.http.HttpServletResponse;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.sql.*
;
import
java.sql.*
;
@WebServlet
(
"/conexion"
)
public
class
BD
{
public
class
BD
extends
HttpServlet
{
Connection
connection
;
public
static
Connection
getConnection
(){
public
void
init
()
{
Connection
con
=
null
;
try
{
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
Class
.
forName
(
"org.postgresql.Driver"
);
con
nection
=
DriverManager
con
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5432/bootcamp_market"
,
.
getConnection
(
"jdbc:postgresql://localhost:5432/bootcamp_market"
,
"postgres"
,
"
postgres
"
);
"postgres"
,
"
Joserba84
"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
System
.
err
.
println
(
e
.
getClass
().
getName
()+
": "
+
e
.
getMessage
());
System
.
err
.
println
(
e
.
getClass
().
getName
()+
": "
+
e
.
getMessage
());
System
.
exit
(
0
);
System
.
exit
(
0
);
}
}
return
con
;
}
}
@Override
public
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
res
)
{
try
{
Statement
stmt
=
connection
.
createStatement
();
res
.
setContentType
(
"text/html"
);
PrintWriter
out
=
res
.
getWriter
();
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;"
);
out
.
println
(
"<html>"
);
out
.
println
(
"<body>"
);
while
(
rs
.
next
())
{
String
nombre
=
rs
.
getString
(
"nombre"
);
String
apellido
=
rs
.
getString
(
"apellido"
);
int
cantidad
=
rs
.
getInt
(
"Cantidad_factura"
);
out
.
println
(
"<p>NOMBRE = \\"
+
nombre
+
"</p>"
);
out
.
println
(
"<p>APELLIDO = \\"
+
apellido
+
"</p>"
);
out
.
println
(
"<p>CANTIDAD FACTURA = \\"
+
cantidad
+
"</p>"
);
}
out
.
println
(
"</body>"
);
out
.
println
(
"</html>"
);
rs
.
close
();
stmt
.
close
();
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
e
.
getClass
().
getName
()
+
": "
+
e
.
getMessage
());
}
}
public
void
destroy
()
{
try
{
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
}
src/main/java/com/roshka/bootcamp/ConsultaClienteFactura.java
0 → 100644
View file @
8f3f5128
package
com
.
roshka
.
bootcamp
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.annotation.WebServlet
;
import
jakarta.servlet.http.HttpServlet
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
java.io.PrintWriter
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
@WebServlet
(
"/consultas"
)
public
class
ConsultaClienteFactura
extends
HttpServlet
{
@Override
public
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
res
)
{
String
respuesta
=
req
.
getParameter
(
"consulta"
);
if
(
respuesta
.
equals
(
"consulta1"
)){
consulta1
(
res
);
}
else
if
(
respuesta
.
equals
(
"consulta2"
)){
consulta2
(
res
);
}
}
private
void
consulta1
(
HttpServletResponse
res
)
{
try
{
Statement
stmt
=
BD
.
getConnection
().
createStatement
();
res
.
setContentType
(
"text/html"
);
PrintWriter
out
=
res
.
getWriter
();
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;"
);
out
.
println
(
"<html>"
);
out
.
println
(
"<body>"
);
while
(
rs
.
next
())
{
String
nombre
=
rs
.
getString
(
"nombre"
);
String
apellido
=
rs
.
getString
(
"apellido"
);
int
cantidad
=
rs
.
getInt
(
"Cantidad_factura"
);
out
.
println
(
"<p>NOMBRE = \\"
+
nombre
+
"</p>"
);
out
.
println
(
"<p>APELLIDO = \\"
+
apellido
+
"</p>"
);
out
.
println
(
"<p>CANTIDAD FACTURA = \\"
+
cantidad
+
"</p>"
);
}
out
.
println
(
"</body>"
);
out
.
println
(
"</html>"
);
rs
.
close
();
stmt
.
close
();
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
e
.
getClass
().
getName
()
+
": "
+
e
.
getMessage
());
}
}
private
void
consulta2
(
HttpServletResponse
res
)
{
try
{
Statement
stmt
=
BD
.
getConnection
().
createStatement
();
res
.
setContentType
(
"text/html"
);
PrintWriter
out
=
res
.
getWriter
();
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"
);
out
.
println
(
"<html>"
);
out
.
println
(
"<body>"
);
out
.
print
(
"<b>Moneda "
+
"- "
+
"Cantidad</b><hr>"
);
while
(
rs
.
next
())
{
String
nombre
=
rs
.
getString
(
"nombre"
);
String
cantidad
=
rs
.
getString
(
"Cantidad"
);
out
.
print
(
"<h5>"
+
nombre
+
" = \t"
+
cantidad
+
"</h5>"
);
}
out
.
println
(
"</body>"
);
out
.
println
(
"</html>"
);
rs
.
close
();
stmt
.
close
();
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
e
.
getClass
().
getName
()
+
": "
+
e
.
getMessage
());
}
}
public
void
destroy
()
{
try
{
BD
.
getConnection
().
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
src/main/webapp/index.jsp
View file @
8f3f5128
<html>
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Home
</title>
</head>
<body>
<body>
<h2>
Anda a alguna URL
</h2>
<h1>
Bienvenido
</h1>
<hr>
<form
action=
"/servlets/consultas"
method=
"get"
>
<input
type=
"hidden"
name=
"consulta"
value=
"consulta1"
>
<button
type=
"submit"
>
Consulta 1
</button>
</form><br>
<form
action=
"/servlets/consultas"
method=
"get"
>
<input
type=
"hidden"
name=
"consulta"
value=
"consulta2"
>
<button
type=
"submit"
>
Consulta 2
</button>
</form><br>
</body>
</body>
</html>
</html>
\ No newline at end of file
target/classes/com/roshka/bootcamp/BD.class
View file @
8f3f5128
No preview for this file type
target/classes/com/roshka/bootcamp/ConsultaClienteFactura.class
0 → 100644
View file @
8f3f5128
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment