ProgramacionFacil

UNIDAD 7: JAVA JSP INTRODUCION A LAS BASES DE DATOS

TEMA 12: BAJA O ELIMINACION SQL DELETE JAVA JSP

Eliminación es otro proceso simple y comun con las bases de datos el modelo que estamos usando hace este tipo de operaciones muy faciles:

La instrucción sql a usar es: DELETE FROM TABLA WHERE CONDICION

Y RESULTSET.EXECUTEUPDATE()

Prog38.jsp


<%@ page import="java.io.*,java.util.*,java.net.*,java.sql.*" %>

<%

// declarando y creando objetos globales

Connection canal = null;

ResultSet tabla= null;

Statement instruccion=null;

String sitiobase = "c:/pfacil/mibase.mdb";

String strcon= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + sitiobase;

if(request.getParameter("OK") != null)

{

// abriendo canal o enlace en su propio try-catch

try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

canal=DriverManager.getConnection(strcon);

instruccion = canal.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

ResultSet.CONCUR_UPDATABLE);

} catch(java.lang.ClassNotFoundException e){} catch(SQLException e) {};

// preparando condicion de eliminacion

int clave = Integer.parseInt(request.getParameter("CLAVEB"));

// construyendo select con condicion eliminacion SQL DELETE

String q="delete from mitabla where clave = "+clave;

// mandando SQL a tabla en disco

try { instruccion.executeUpdate(q);

// avisando

out.println("registro eliminado");

} //fin try no usar ; al final de dos o mas catchs

catch(SQLException e) {}

catch(java.lang.NullPointerException e){};

try {

// no ocupa cerrar tabla()

instruccion.close();canal.close();} catch(SQLException e) {};

};

// construyendo forma dinamica

out.println("<FORM ACTION=prog38.jsp METHOD=post>");

out.println("CLAVE ELIMINAR:<INPUT TYPE=TEXT NAME=CLAVEB><BR>");

out.println("<INPUT TYPE=SUBMIT NAME=OK VALUE=ELIMINAR><BR>");

out.println("</FORM>");

%>

Corridas :

Prog ←-tabla original

image65.jpg

pro38.html

image66.jpg

prog33.jsp

image67.jpg

TAREAS PROGRAMACION JAVA JSP

1.- construir este proceso para las tablas y bases de datos que tengan construidas.

 




 


Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki

Politica de Privacidad