altas y consultas
En el HTML
<html><head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h3> Tecnicas de programacion con calidad </h3>
<form action="altas.jsp" method="post" name="altas">
Dato <input type="text" name="dato1">
<input type="submit" name="alta" value="Alta">
</form>
<form action="consultas.jsp" method="post" name="consultas">
consultar: <input type="text" name="dato1">
<input type="submit" name="consulta" value="Consulta">
</form>
</body>
</html>
En el jsp altas
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%@page import="java.sql.*,java.io.*" %>
<%
String dat1=request.getParameter("dato1");
PreparedStatement ps=null;
Connection con=null;
Class.forName("com.mysql.jdbc.Driver");
con= DriverManager.getConnection("jdbc:mysql://localhost/calidad", "root", "n0m3l0");
String querystring="insert into dato values(?)";
ps=con.prepareStatement(querystring);
ps.setString(1, dat1);
ps.executeUpdate();
out.println("<script>alert('dado de alta') </script>");
%>
</body>
</html>
En el jsp consultas
<html>
<body>
<%@page import="java.sql.*,java.io.*" %>
<%
String cad;
Connection c=null;
Statement s=null;
ResultSet r=null;
cad=request.getParameter("dato1");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
c=DriverManager.getConnection("jdbc:mysql://localhost/calidad","root", "n0m3l0");
s=c.createStatement();
}
catch (SQLException error)
{
out.println(error.toString());
}
try{
String quer="select * from dato where dato1=?";
PreparedStatement ps=c.prepareStatement(quer);
ps.setString(1,cad);
r=ps.executeQuery();
if(r.next()){
String dat=r.getString("dato1");
out.println(dat);
out.println("<script>alert('consulta exitosa')</script>");
}else
{
out.println("<script>alert('no existe')</script>");
}
}
catch (SQLException error)
{
out.println(error.toString());
}
%>
</body>
<html>
Tiempo: 36 minutos
No hay comentarios.:
Publicar un comentario