Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/06/2009, 20:22
Coplo
 
Fecha de Ingreso: octubre-2008
Mensajes: 155
Antigüedad: 15 años, 6 meses
Puntos: 1
Como puedo crear un formulario que guarde en 3 diferentes tablas

Bueno lo que quisiera saber si me pueden ayudar a como guardar datos en 3 diferentes tablas, este es mi codigo:

mostrar_grupos.jsp
<%@ include file="conecta.jsp" %>
Código HTML:
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mostrar grupos</title>
</head>

<body>
<h2>Grupos</h2>
<p><a href="crear_grupo.jsp">Agregar grupo</a></p>
<table width="500" border="1" align="center">
  <tr>
    <th width="34">Id</th>
    <th width="138">Nombre</th>
    <th> Descripción</th>
  </tr>
  
  <% 
  COMANDO="select * from grupos";
  
  rset = stmt.executeQuery(COMANDO);
  while(rset.next()){
  %>
  <tr>
    <td><%= rset.getInt("id") %></td>
    <td><%= rset.getString("nombre") %></td>
    <td><%= rset.getString("descripcion") %></td>
  </tr>
  <% } %>
  
  <% rset.close(); %>
  
</table>
</body>
</html> 
crear_grupo.jsp
Código HTML:
<%@ include file="conecta.jsp" %>
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Crear grupo</title>
</head>

<body>
 <h2>Crear grupo </h2>
 <p>&nbsp; </p>
 <form id="form1" name="form1" method="post" action="grabar_grupo.jsp">
  <table width="400" border="1" align="center">
     <tr>
       <td width="80">&nbsp;</td>
       <td width="304">&nbsp;</td>
     </tr>
     <tr>
       <td>Nombre:</td>
       <td><input type="text" name="f_nombre" id="f_nombre" /></td>
     </tr>
     <tr>
       <td>Descripcion:</td>
       <td><textarea name="f_descripcion" id="f_descripcion" cols="45" rows="5"></textarea></td>
     </tr>
     <tr>
       <td>&nbsp;</td>
       <td><label>
         <select name="select" id="select">
           <option>Matematica</option>
           <option>Historia</option>
           <option>Quimica</option>
         </select>
       </label></td>
     </tr>
     <tr>
       <td>&nbsp;</td>
       <td><input type="submit" name="button" id="button" value="Enviar" /></td>
     </tr>
   </table>
  </form>
</body>
</html> 
grabar_grupo.jsp
Código HTML:
<%@ include file="conecta.jsp" %>

<%
	String nombre = request.getParameter("f_nombre");
	String descripcion = request.getParameter("f_descripcion");
	
	int enviar=0;
	
		COMANDO="insert into grupos values(null,'"+nombre+"','"+descripcion+"')";
		enviar = stmt.executeUpdate(COMANDO);
		response.sendRedirect("mostrar_grupos.jsp");
%> 
conecta.jsp
Código HTML:
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>

<%

Connection conn = null;
Statement stmt = null;
ResultSet rset = null;

String COMANDO = "";

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/libreria");
stmt = conn.createStatement();

%> 
La base de datos se llama libreria y las 3 tablas se llaman matematica, historia y quimica, con los campos id, nombre y descripcion.

Lo que quisiera saber es como puedo hacer para que cuando el libro sea de matematica se guarde en la tabla de matematica ó cuando el libro sea de quimica se guarde en la tabla quimica.
Espero que me puedan entender y ayudar GRACIAS.