Sie sind auf Seite 1von 9

FORMULARIO CON CAPAS

Lee atentamente las indicaciones, desarrllalo y enva tu archivo a travs de este


medio:
Desarrollar un formulario donde se ingrese un cdigo de artculo y al hacer click en
un botn se elimine. En un documento de Word poner el cdigo de lo siguiente:
Procedimientos Almacenados, Capa Datos, Capa Negocio, Capa Entidad, JSP.
Finalmente comprima sus archivos en un Winrar y envelo.
CODIGOS DE DESARROLLO

CREATE PROCEDURE speliminar(`codigo` VARCHAR(4))


DELETE FROM `articulo`WHERE codigo=cdigo

CAPA DATOS
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package capadatos;
import java.sql.*;
/**
*
* @author Javier
*/

public class Datos {


public Connection cn=null;
public String runQuery(String nomsp,Object[] arreglo ){
String resultado="";
try {
String usuario = "root";
String password = "0909";
String servidor = "localhost";
String puerto = "3306";
String basedatos = "test";
String url = "jdbc:mysql://" + servidor + ":" + puerto + "/" + basedatos;
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection(url, usuario, password);
CallableStatement cmd;
cmd=cn.prepareCall(nomsp);
for(int i=0;i<arreglo.length;i++){
cmd.setObject(i+1, arreglo[i]);
}
cmd.executeUpdate();
resultado="se realizaron los cambios";
} catch (Exception e) {
resultado= e.getMessage();
}
return resultado;
}

public ResultSet dataQuery(String nomsp,Object[] arreglo ){


ResultSet resultado=null;
try {
String usuario = "root";
String password = "0909";
String servidor = "localhost";
String puerto = "3306";
String basedatos = "test";
String url = "jdbc:mysql://" + servidor + ":" + puerto + "/" + basedatos;
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection(url, usuario, password);
CallableStatement cmd;
cmd=cn.prepareCall(nomsp);
for(int i=0;i<arreglo.length;i++){
cmd.setObject(i+1, arreglo[i]);
}

resultado=cmd.executeQuery();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return resultado;
}
}

CAPA NEGOCIO
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package capanegocio;

import capadatos.Datos;
import capaentidad.EnArticulo;
import java.util.*;
import java.sql.*;

/**
*
* @author Javier
*/
public class NeArticulo {

public String eliminar(EnArticulo obj){


String resultado;
try {
Datos objdatos=new Datos();

resultado=objdatos.runQuery("{call speliminar(?)}",
new Object[]{obj.getCodigo()});

} catch (Exception e) {
resultado=e.getMessage();
}
return resultado;
}

CAPA ENTIDAD
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package capaentidad;

/**
*
* @author Javier
*/
public class EnArticulo {
/*`articulo```````*/

private String codigo;


private String nombre;
private String precio;

/**
* @return the codigo
*/
public String getCodigo() {
return codigo;
}

/**
* @param codigo the codigo to set
*/
public void setCodigo(String codigo) {
this.codigo = codigo;
}

/**
* @return the nombre
*/
public String getNombre() {
return nombre;
}

/**
* @param nombre the nombre to set
*/
public void setNombre(String nombre) {
this.nombre = nombre;
}

/**
* @return the precio
*/
public String getPrecio() {
return precio;
}

/**
* @param precio the precio to set
*/
public void setPrecio(String precio) {
this.precio = precio;
}
}

ELIMINAR ARTICULO JSP


<%-Document : GrabarArticulo
Created on : 07/07/2014, 11:50:28 PM
Author

: Javier

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@page import="capaentidad.*,capanegocio.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>ELIMINAR ARTICULO</h1>
<%
String codigo=request.getParameter("codigo");
EnArticulo objenar=new EnArticulo();
NeArticulo objnear=new NeArticulo();
objenar.setCodigo(codigo);
out.print(objnear.eliminar(objenar));
%>
<form id="frm1" method="post">

<input type="text" id="codigo" name="codigo"/>


<input type="submit" value="ELIMINAR" />

</form>
</body>
</html>

Das könnte Ihnen auch gefallen