capturar datos en jsp
Hola, tengo una p谩gina jsp con un formulario de ingreso de datos de un paciente. la pagina tiene codigo para insertar esos datos en mysql pero no los inserta. aca va el c贸digo:
<%--Esta p谩gina se llama Registro.jsp--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection"%>
<%@ page import = "java.sql.DriverManager"%>
<%@ page import = "java.sql.ResultSet"%>
<%@ page import = "java.sql.Statement"%>
<%@ page import = "java.sql.*"%>
<%
//declaraci贸n de variables globales
Statement stmt_consul=null, stmt_inser = null;
ResultSet rs = null;
Connection conn= null;
String dns="jdbc:odbc:clinica";
//conexion a la base de datos
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn =
DriverManager.getConnection("dns,root,admin");
}catch(Exception ex) {}
//insersi贸n de datos
String enviar=request.getParameter("enviar");
if(enviar==null)enviar="";
if(enviar.compareTo("enviar")==0){
try{
stmt_inser = conn.createStatement();
int codigo=Integer.parseInt( request.getParameter("codigo"));
String nombre=request.getParameter("nombre");
String apellido=request.getParameter("apellido");
String direccion=request.getParameter("direccion");
int id_obrasocial=Integer.parseInt(request.getParameter("id_obrasocial"));
String usuario=request.getParameter("usuario");
String password=request.getParameter("password");
String strSQL= "INSERT INTO paciente(codigo,nombre,apellido,direccion,id_obrasocial,usuario,password) values('" + codigo + "','" + nombre + "','" + apellido + "','" + direccion + "','" + id_obrasocial + "','" + usuario + "','" + password + "')";
stmt_inser.executeUpdate(strSQL);
out.println("Insersi贸n exitosa");
} catch (Exception ex) {}
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="es" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Reserva de Turnos de Clinica del</title>
<style type="text/css">
.style1 {
font-size: x-large;
}
.style2 {
margin-bottom: 0px;
}
.style3 {
text-align: center;
}
.style4 {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="layer1" class="style1" style="position: absolute; width: 375px; height: 32px; z-index: 1; left: 225px; top: 23px">
Reserva de Turnos de Clinica del Sol</div>
<p> </p>
<p> </p>
<form action="Registro.jsp" method="post" style="height: 484px; width: 519px;">
<div class="style3" style="width: 522px; height: 481px">
<label id="Label1"><span class="style4"><strong>Registro de Paciente</strong></span><br />
<br />
<br />
<br />
C贸digo: <input name="codigo" type="text" /><br />
<br />
Nombre: </label><input class="style2" name="nombre" type="text" /><br />
<br />
Apellido: <input name="apellido" type="text" /><br />
<br />
Direcci贸n: <input name="direccion" type="text" /><br />
<br />
ID_Obra Social: <input name="id_obrasocial" type="text" /><br />
<br />
Usuario: <input class="style2" name="usuario" type="text" /><br />
<br />
Constrase帽a: <input name="password" type="password" /><br />
<br />
<br />
<br />
<br />
<input name="enviar" style="width: 139px" type="submit" value="enviar" /><input name="Reset1" style="width: 152px" type="reset" value="restablecer" /><br />
</div>
</form>
</body>
</html>
<% //cerrar la conexion
try {
rs.close();
stmt_consul.close();
conn.close();
} catch (Exception sqlEx) {}
%>
<%--Esta p谩gina se llama Registro.jsp--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.Connection"%>
<%@ page import = "java.sql.DriverManager"%>
<%@ page import = "java.sql.ResultSet"%>
<%@ page import = "java.sql.Statement"%>
<%@ page import = "java.sql.*"%>
<%
//declaraci贸n de variables globales
Statement stmt_consul=null, stmt_inser = null;
ResultSet rs = null;
Connection conn= null;
String dns="jdbc:odbc:clinica";
//conexion a la base de datos
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn =
DriverManager.getConnection("dns,root,admin");
}catch(Exception ex) {}
//insersi贸n de datos
String enviar=request.getParameter("enviar");
if(enviar==null)enviar="";
if(enviar.compareTo("enviar")==0){
try{
stmt_inser = conn.createStatement();
int codigo=Integer.parseInt( request.getParameter("codigo"));
String nombre=request.getParameter("nombre");
String apellido=request.getParameter("apellido");
String direccion=request.getParameter("direccion");
int id_obrasocial=Integer.parseInt(request.getParameter("id_obrasocial"));
String usuario=request.getParameter("usuario");
String password=request.getParameter("password");
String strSQL= "INSERT INTO paciente(codigo,nombre,apellido,direccion,id_obrasocial,usuario,password) values('" + codigo + "','" + nombre + "','" + apellido + "','" + direccion + "','" + id_obrasocial + "','" + usuario + "','" + password + "')";
stmt_inser.executeUpdate(strSQL);
out.println("Insersi贸n exitosa");
} catch (Exception ex) {}
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="es" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Reserva de Turnos de Clinica del</title>
<style type="text/css">
.style1 {
font-size: x-large;
}
.style2 {
margin-bottom: 0px;
}
.style3 {
text-align: center;
}
.style4 {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="layer1" class="style1" style="position: absolute; width: 375px; height: 32px; z-index: 1; left: 225px; top: 23px">
Reserva de Turnos de Clinica del Sol</div>
<p> </p>
<p> </p>
<form action="Registro.jsp" method="post" style="height: 484px; width: 519px;">
<div class="style3" style="width: 522px; height: 481px">
<label id="Label1"><span class="style4"><strong>Registro de Paciente</strong></span><br />
<br />
<br />
<br />
C贸digo: <input name="codigo" type="text" /><br />
<br />
Nombre: </label><input class="style2" name="nombre" type="text" /><br />
<br />
Apellido: <input name="apellido" type="text" /><br />
<br />
Direcci贸n: <input name="direccion" type="text" /><br />
<br />
ID_Obra Social: <input name="id_obrasocial" type="text" /><br />
<br />
Usuario: <input class="style2" name="usuario" type="text" /><br />
<br />
Constrase帽a: <input name="password" type="password" /><br />
<br />
<br />
<br />
<br />
<input name="enviar" style="width: 139px" type="submit" value="enviar" /><input name="Reset1" style="width: 152px" type="reset" value="restablecer" /><br />
</div>
</form>
</body>
</html>
<% //cerrar la conexion
try {
rs.close();
stmt_consul.close();
conn.close();
} catch (Exception sqlEx) {}
%>
