Commit faa5b115 by OscarGonzalez97

se agregan parametros iniciales

parent 594dd0d1
package com.roshka.bootcamp; package com.roshka.bootcamp;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.annotation.WebInitParam;
import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
...@@ -8,18 +10,22 @@ import jakarta.servlet.http.HttpServletResponse; ...@@ -8,18 +10,22 @@ import jakarta.servlet.http.HttpServletResponse;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.sql.*; import java.sql.*;
@WebServlet("/conexion") @WebServlet(urlPatterns = "/conexion", initParams = {@WebInitParam(name = "dbUrl", value = "jdbc:postgresql://localhost:5432/bootcamp_market"),
@WebInitParam(name = "dbUser", value = "postgres"),
@WebInitParam(name = "dbPassword", value = "postgres"),
})
public class BD extends HttpServlet { public class BD extends HttpServlet {
Connection connection; Connection connection;
public void init() {
public void init(ServletConfig config) {
try { try {
Class.forName("org.postgresql.Driver"); Class.forName("org.postgresql.Driver");
connection = DriverManager connection = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/bootcamp_market", .getConnection(config.getInitParameter("dbUrl"), config.getInitParameter("dbUser"), config.getInitParameter("dbPassword"));
"postgres", "postgres");
} 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);
} }
} }
...@@ -43,9 +49,9 @@ public class BD extends HttpServlet { ...@@ -43,9 +49,9 @@ public class BD extends HttpServlet {
String apellido = rs.getString("apellido"); String apellido = rs.getString("apellido");
int cantidad = rs.getInt("Cantidad_factura"); int cantidad = rs.getInt("Cantidad_factura");
out.println("<p>NOMBRE = \\" + nombre + "</p>"); out.println("<p>NOMBRE = " + nombre + "</p>");
out.println("<p>APELLIDO = \\" + apellido + "</p>"); out.println("<p>APELLIDO = " + apellido + "</p>");
out.println("<p>CANTIDAD FACTURA = \\" + cantidad + "</p>"); out.println("<p>CANTIDAD FACTURA = " + cantidad + "</p>");
} }
out.println("</body>"); out.println("</body>");
......
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