Modulo 3.1 Codigo - Guardar
Modulo 3.1 Codigo - Guardar
Document : inicio1
Created on : 19 abr 2024, 09:05:53
Author : JESSI PEREZ
--%>
<%@page import="java.sql.*"%>
<%@page import="com.mysql.jdbc.Driver"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<title>Listado de Ingresos</title>
</head>
<body>
<%
Connection con = null;
Statement st = null;
ResultSet rs = null;
%>
<div class="container mt-5">
<div class="row">
<div class="col-sm">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Tipo de Ingreso</th>
<th scope="col">Nombre</th>
<th scope="col">Precio</th>
</tr>
</thead>
<tbody>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/tegnology?
serverTimezone=UTC","root", "123456");
st = con.createStatement();
rs = st.executeQuery("SELECT * FROM
Registrar_ingresos;");
while (rs.next()) {
%>
<tr>
<th scope="row"><%= rs.getInt("id_ingresos") %></th>
<td><%= rs.getString("registrar_egresos") %></td>
<td><%= rs.getString("nombre") %></td>
<td>$<%= rs.getDouble("precio") %></td>
</tr>
<%
}
} catch (Exception e) {
out.print("error mysql "+e);
}
%>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
<%--
Document : inicio2
Created on : 19 abr 2024, 09:11:26
Author : JESSI PEREZ
--%>
<%@page import="java.sql.*"%>
<%@page import="com.mysql.jdbc.Driver"%>
<%@page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<title>Registro</title>
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-sm">
<form action="inicio2.jsp" method="post">
<div class="form-group">
<label for="registrar_egresos">Tipo de Ingreso</label>
<input type="text" class="form-control"
id="registrar_egresos" name="registrar_egresos" placeholder="Tipo de ingreso"
required="required">
</div>
<div class="form-group">
<label for="nombre">Nombre</label>
<input type="text" class="form-control" id="nombre"
name="nombre" placeholder="Nombre" required="required">
</div>
<div class="form-group">
<label for="precio">Precio</label>
<input type="number" step="0.01" class="form-control"
id="precio" name="precio" placeholder="Precio" required="required">
</div>
<button type="submit" name="enviar" class="btn btn-
primary">Guardar Ingreso <i class="fa fa-floppy-o" aria-hidden="true"></i></button>
</form>
</div>
</div>
</div>
<%
if (request.getParameter("enviar") != null) {
String registrar_egresos = request.getParameter("registrar_egresos");
String nombre = request.getParameter("nombre");
double precio = Double.parseDouble(request.getParameter("precio"));
try {
Connection con = null;
Statement st = null;
Class.forName("com.mysql.jdbc.Driver");
con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/tegnology?
serverTimezone=UTC", "root", "123456");
st = con.createStatement();
st.executeUpdate("INSERT INTO Registrar_ingresos
(registrar_egresos, nombre, precio) VALUES ('"+registrar_egresos+"', '"+nombre+"',
"+precio+");");
request.getRequestDispatcher("inicio1.jsp").forward(request,
response);
} catch (Exception e) {
out.print(e);
}
}
%>
</body>
</html>