Você está na página 1de 13

PROGRAMACIN AVANZADA I

Avances de las actividades de la clase.


Se tiene un proyecto con la siguiente estructura:

El contenido de la clase Conex.java, ya lo conocen, sin embargo les dejo el


cdigo.
package datos;
import java.sql.*;
import javax.swing.JOptionPane;
public class Conex {
public Connection Conectarse(){
Connection link = null;
String url = "jdbc:mysql://localhost:3306/claseproavz";
try {
Class.forName("com.mysql.jdbc.Driver");
}catch (ClassNotFoundException ex){
JOptionPane.showMessageDialog(null,"Driver No
encontrado","Mensaje",0);
}
try {
link = DriverManager.getConnection(url, "root","");
}catch(SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage() ,"Mensaje",0);
}
return link;
}
}

El archivo frmEstudiantes.jsp, y su cdigo.


%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
<%@ page import="datos.Conex"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script LANGUAGE="JavaScript">
function confirmSubmit()
{
var res=confirm("Esta seguro de eliminar el registro?");
if (res)
return true ;
else
return false ;
}
</script>
</head>
<body>
<%
datos.Conex Ls = new datos.Conex();
Connection link = Ls.Conectarse();
String ConSQL = "Select * FROM tbestudiantes";
%>
<h1>Estudiantes</h1><br>
<table border="1" align="center">
<thead>
<tr>
<th colspan="9">
<form action="frmnuevo.jsp">
<input type="submit" value="Nuevo" />
</form></th>
</tr>
<tr>
<th>Ver</th>
<th>Editar</th>
<th>Eliminar</th>
<th>Documento</th>
<th>Nombres</th>
<th>Apellidos</th>
<th>Direccin</th>
<th>Correo</th>
</tr>
</thead>
<tbody>

<%
try {
ResultSet rs = link.createStatement().executeQuery(ConSQL);
while (rs.next()){
String Documento = rs.getString(1);
%>
<tr>
<td><A HREF ="frmver.jsp?Documento=<%
out.print(Documento); %>">Ver</a> </td>
<td align="center" >
<A HREF ="frmmodificarestudiante.jsp?
Documento='78742034'">
<img src="img/editar.png" width="15" height="15"
alt="Editar Registro"/>
</a>
</td>
<td>
<form action="frmeliminar.jsp">
<input type="submit" value="Eliminar" onclick="return
confirmSubmit();" />
<input type="hidden" name="TxtDocumento" value="<%
out.print(Documento); %>" />
</form>
</td>
<td><%
<td><%
<td><%
<td><%
<td><%
</tr>

out.print(Documento); %> </td>


out.print(rs.getString(2)); %></td>
out.print(rs.getString(3)); %></td>
out.print(rs.getString(4)); %></td>
out.print(rs.getString(5)); %></td>

<%
}
rs.close();
}
catch(SQLException ex){
out.print("Error: " + ex.getMessage().toString() );
}
%>
</tbody>
</table>
</body>
</html>

frmnuevo.jsp y su cdigo
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Nuevo Estudiante</h1>
<form action="frmgrabarnuevo.jsp">
<table border="1">
<thead>
<tr>
<th colspan="2"> Ingrese datos nuevo estudiante</th>
</tr>
</thead>
<tbody>
<tr>
<td>Documento</td>
<td><input type="text" name="TxtDocumento" value=""
/></td>
</tr>
<tr>
<td>Nombres</td>
<td><input type="text" name="TxtNombres" value=""
/></td>
</tr>
<tr>
<td>Apellidos</td>
<td><input type="text" name="TxtApellidos" value=""
/></td>
</tr>
<tr>
<td>Direccin</td>
<td><input type="text" name="TxtDireccion" value=""
/></td>
</tr>
<tr>
<td>Correo</td>
<td><input type="text" name="TxtCorreo" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Grabar" />
</td>
</tr>
</tbody>
</table>

</form>
</body>
</html>
frmGrabarNuevo.jsp y su cdigo.
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
<%@ page import="datos.Conex"%>
<%
datos.Conex Ls = new datos.Conex();
Connection link = Ls.Conectarse();
String Documento = request.getParameter("TxtDocumento");
String Nombres = request.getParameter("TxtNombres");
String Apellidos = request.getParameter("TxtApellidos");
String Direccion = request.getParameter("TxtDireccion");
String Correo = request.getParameter("TxtCorreo");
String ConSQL = "INSERT INTO tbestudiantes values('" + Documento +
"','" + Nombres + "','" + Apellidos + "','" + Direccion + "','" +
Correo + "')";
link.createStatement().execute(ConSQL);
out.print("<script language=Javascript>alert('Estudiante
Ingresado');</script>");
out.print("<script
language=Javascript>location.href=\"frmEstudiantes.jsp\";</script>");
%>
frmVer.jsp y su cdigo.
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
<%@ page import="datos.Conex"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Nuevo Estudiante</h1>
<%
datos.Conex Ls = new datos.Conex();
Connection link = Ls.Conectarse();
String ConSQL = "Select * FROM tbestudiantes "
+ " WHERE DocumentoEstudiante='" +
request.getParameter("Documento") + "'";
try{
ResultSet rs = link.createStatement().executeQuery(ConSQL);
if (rs.next()) {

%>
<form action="frmEstudiantes.jsp">
<table border="1">
<thead>
<tr>
<th colspan="2"> Datos del estudiante</th>
</tr>
</thead>
<tbody>
<tr>
<td>Documento</td>
<td><% out.print(rs.getString(1)); %></td>
</tr>
<tr>
<td>Nombres</td>
<td><% out.print(rs.getString(2)); %></td>
</tr>
<tr>
<td>Apellidos</td>
<td><% out.print(rs.getString(3)); %></td>
</tr>
<tr>
<td>Direccin</td>
<td><% out.print(rs.getString(4)); %></td>
</tr>
<tr>
<td>Correo</td>
<td><% out.print(rs.getString(5)); %></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Volver" />
</td>
</tr>
</tbody>
</table>
</form>
<%
}
}
catch(SQLException ex){
out.print("Error: " + ex.getMessage().toString() );
}
%>
</body>
</html>

frmEliminar.jsp y su cdigo.
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
<%@ page import="datos.Conex"%>
<%
datos.Conex Ls = new datos.Conex();
Connection link = Ls.Conectarse();
String Documento = request.getParameter("TxtDocumento");
String ConSQL = "DELETE FROM tbestudiantes where
DocumentoEstudiante='" +
Documento + "'";
link.createStatement().execute(ConSQL);
out.print("<script language=Javascript>alert('Estudiante
Eliminado');</script>");
out.print("<script
language=Javascript>location.href=\"frmEstudiantes.jsp\";</script>");
%>
frmmodificarestudiante.jsp y su cdigo.
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
<%@ page import="datos.Conex"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Modificar Estudiante</h1>
<%
datos.Conex Ls = new datos.Conex();
Connection link = Ls.Conectarse();
String ConSQL = "Select * FROM tbestudiantes "
+ " WHERE DocumentoEstudiante='" +
request.getParameter("Documento") + "'";
try{
ResultSet rs = link.createStatement().executeQuery(ConSQL);
if (rs.next()) {
String Documento = rs.getString(1);
%>
<form action="frmgrabarmodificacion.jsp">
<table border="1">
<thead>
<tr>
<th colspan="2"> Ingrese datos nuevo estudiante</th>

</tr>
</thead>
<tbody>
<tr>
<td>Documento</td>
<td>
<% out.print(Documento); %>
<input type="hidden" name="TxtDocumento" value=" <%
out.print(Documento); %>" />
</td>
</tr>
<tr>
<td>Nombres</td>
<td><input type="text" name="TxtNombres" value="<%
out.print(rs.getString(2)); %>" /></td>
</tr>
<tr>
<td>Apellidos</td>
<td><input type="text" name="TxtApellidos" value="<%
out.print(rs.getString(3)); %>" /></td>
</tr>
<tr>
<td>Direccin</td>
<td><input type="text" name="TxtDireccion" value="<%
out.print(rs.getString(4)); %>" /></td>
</tr>
<tr>
<td>Correo</td>
<td><input type="text" name="TxtCorreo" value="<%
out.print(rs.getString(5)); %>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Grabar" />
</td>
</tr>
</tbody>
</table>
</form>
<%
}
}
catch(SQLException ex){
out.print("Error: " + ex.getMessage().toString() );
}
%>
</body>
</html>

frmgrabarmodificacion.jsp y su cdigo.
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
<%@ page import="datos.Conex"%>
<%
datos.Conex Ls = new datos.Conex();
Connection link = Ls.Conectarse();
String Documento = request.getParameter("TxtDocumento");
String Nombres = request.getParameter("TxtNombres");
String Apellidos = request.getParameter("TxtApellidos");
String Direccion = request.getParameter("TxtDireccion");
String Correo = request.getParameter("TxtCorreo");
String ConSQL = "UPDATE tbestudiantes SET
Nombres='"+Nombres+"',Apellidos='"+Apellidos+"',Direccion='"+Direccion+"'
,Correo='"+Correo+"' WHERE DocumentoEstudiante="+ Documento;
link.createStatement().execute(ConSQL);
out.print("<script language=Javascript>alert('Estudiante
Actualizado');</script>");
out.print("<script
language=Javascript>location.href=\"frmEstudiantes.jsp\";</script>");
%>
estilo.css y su cdigo
BODY {
font-family: Verdana, sans-serif, Arial;
font-weight: bold;
font-size: .9em;
color:#000000;
background-color:#ffffff;
background-repeat:no-repeat;
background-attachment:fixed;
margin: 0px 0px;
}
a.sinsubraya
{
text-decoration:none;
color:#ff0000;
font-weight: bold;
}
a.sinsubraya:hover
{
color:#000000;
text-decoration:underline;
font-weight: bold;

}
TABLE
{
width:90%;
background-color: #ffffff;
border: 1px #000000 solid;
border-collapse: collapse;
border-spacing: 0px;
}
TABLE.ficha
{
width:60%;
background-color: #ffffff;
border: 1px #000000 solid;
border-collapse: collapse;
border-spacing: 0px;
}
TABLE.mensaje
{
width:460px;
background-color: #ffffff;
border: 0px;
}
TABLE.mensaje2
{
width:90%;
background-color: #ffffff;
border: 1px #ffffff solid;
border-collapse: collapse;
border-spacing: 0px;
}
TD
{
border-bottom: 1px #0C9816 dotted;
text-align: left;
font-family: Verdana, sans-serif, Arial;
font-weight: bold;
font-size: .9em;
color: #000000;
background-color: #ffffff;
}
TD.derecha
{
border-bottom: 1px #0C9816 dotted;

text-align: right;
font-family: Verdana, sans-serif, Arial;
font-weight: bold;
font-size: .9em;
color: #000000;
background-color: #ffffff;
}
TD.primeralinea
{
border-bottom: 1px #0C9816 dotted;
border: 1px dotted #0c9816;
text-align: center;
font-family: Verdana, sans-serif, Arial;
font-weight: bold;
font-size: .9em;
color: #ffffff;
background-color: #76B77A;
}
TD.primeralineaizquierda
{
border-bottom: 1px #0C9816 dotted;
border: 1px dotted #0c9816;
text-align: left;
font-family: Verdana, sans-serif, Arial;
font-weight: bold;
font-size: .9em;
color: #ffffff;
background-color: #76B77A;
}
TD.segundalinea
{
border-bottom: 1px #0C9816 dotted;
border-right: 1px #0C9816 dotted;
border-left: 1px #0C9816 dotted;
text-align: center;
font-family: Verdana, sans-serif, Arial;
font-weight: normal;
font-size: .6em;
color: #404040;
background-color: #ffffff;
}
TD.segundalineaizquierda
{
border-bottom: 1px #0C9816 dotted;
border-right: 1px #0C9816 dotted;

border-left: 1px #0C9816 dotted;


text-align: left;
font-family: Verdana, sans-serif, Arial;
font-weight: normal;
font-size: .6em;
color: #404040;
background-color: #ffffff;
}
TD.segundalineaderecha
{
border-bottom: 1px #0C9816 dotted;
border-right: 1px #0C9816 dotted;
border-left: 1px #0C9816 dotted;
text-align: right;
font-family: Verdana, sans-serif, Arial;
font-weight: normal;
font-size: .6em;
color: #404040;
background-color: #ffffff;
}
input
{
BACKGROUND-COLOR: #ffff99;
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
FONT-SIZE: 8pt;
border: 1px solid #000000;
}
select
{
BACKGROUND-COLOR: #ffff99;
BORDER-BOTTOM: #0C9816 1px solid;
BORDER-LEFT: #0C9816 1px solid;
BORDER-RIGHT: #0C9816 1px solid;
BORDER-TOP: #0C9816 1px solid;
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
FONT-SIZE: 8pt;
}
textarea
{
BACKGROUND-COLOR: #ffff99;
BORDER-BOTTOM: #0C9816 1px solid;
BORDER-LEFT: #0C9816 1px solid;
BORDER-RIGHT: #0C9816 1px solid;
BORDER-TOP: #0C9816 1px solid;
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;

FONT-SIZE: 7pt;
}
La tabla sobre la cual se ha trabajado.

Ok, all estn las 4 funciones bsicas que se pueden llevar a cabo sobre una
base de datos. Esto debe estar funcionando perfectamente para el prximo
jueves 22 de octubre, individualmente.

Você também pode gostar