Foros del Web » Programación para mayores de 30 ;) » Java »

java beans+jsp+oracle 10g

Estas en el tema de java beans+jsp+oracle 10g en el foro de Java en Foros del Web. hola a todos, toy empezando a programar en netbeans y mi duda es la sgte : tengo un archivo registar_datos.html, el cual contiene inputs para ...
  #1 (permalink)  
Antiguo 19/12/2007, 19:01
 
Fecha de Ingreso: diciembre-2007
Mensajes: 22
Antigüedad: 16 años, 4 meses
Puntos: 0
java beans+jsp+oracle 10g

hola a todos, toy empezando a programar en netbeans y mi duda es la sgte :

tengo un archivo registar_datos.html, el cual contiene inputs para codigo, nombre,creditos,horas teoria,etc, este es el codigo


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title></title>
</head>
<body>
<div align="center">
<h1>REGISTRAR CURSO
</h1>
</div>
<form name="form1" method="post" action="curso_insertado.jsp">
<table width="500" border="1" align="center">
<tr>
<th scope="col"><div align="left"><strong>Codigo</strong></div></th>
<th scope="col"><label>
<div align="left">
<input name="codigo" type="text" id="codigo" size="15">
</div>
</label></th>
</tr>
<tr>
<th scope="col"><div align="left"><strong>Curso</strong></div></th>
<th scope="col"><label>
<div align="left">
<input name="curso" type="text" id="curso" size="60">
</div>
</label></th>
</tr>
<tr>
<td><strong>Creditos</strong></td>
<td><label>
<input name="credito" type="text" id="credito" size="5">
</label></td>
</tr>
<tr>
<td><strong>horas teoria </strong></td>
<td><label>
<input name="horateoria" type="text" id="horateoria" size="5">
</label></td>
</tr>
<tr>
<td><strong>horas practica </strong></td>
<td><label>
<input name="horapractica" type="text" id="horapractica" size="5">
</label></td>
</tr>
<tr>
<td><strong>horas lab </strong></td>
<td><label>
<input name="horalab" type="text" id="horalab" size="5">
</label></td>
</tr>
<tr>
<td><strong>ciclo</strong></td>
<td><label>
<input name="ciclo" type="text" id="ciclo" size="5">
</label></td>
</tr>
<tr>
<td><strong>tipo</strong></td>
<td><label>
<input name="tipo" type="text" id="tipo" size="5">
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center"> <br>
<input type="submit" name="Submit" value="Grabar">
</div></label></td>
</tr>
</table>
</form>



tambien un archivo curso_insertado.jsp, que recibe los parametros del html y muestra un mensaje de confirmacion o error si los datos han sido insertados:


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

<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<% String cod=request.getParameter("codigo");
String nom=request.getParameter("curso");
String cred=request.getParameter("credito");
String horat=request.getParameter("horateoria");
String horap=request.getParameter("horapractica");
String horal=request.getParameter("horalab");
String cicl=request.getParameter("ciclo");
String tip=request.getParameter("tipo");

%>

<jsp:useBean id="con1" scope="page" class="modelo.Conexion" >
<jsp:setProperty name="con1" property="*" />
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<%
out.print(con1.insertar_curso());
if(con1.insertar_curso())
{

%>
<h1>Registro exitoso !!!</h1>
<%
} else {
%>
<h1>No se pudo registrar.....</h1>
<%
}

%>
<jsp:getProperty name="con1" property="cod" />
<jsp:getProperty name="con1" property="curs" />
<jsp:getProperty name="con1" property="cred" />
<jsp:getProperty name="con1" property="horat" />
<jsp:getProperty name="con1" property="horap" />
<jsp:getProperty name="con1" property="horal" />
<jsp:getProperty name="con1" property="cicl" />
<jsp:getProperty name="con1" property="tip" />
</jsp:useBean>

</body>
</html>



modelo es el paquete y conexion es el java bean con el metodo insertar_curso


Ahora tengo el java Bean con el sgte codigo :


package modelo;

import java.beans.*;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.sql.PreparedStatement;



/**
* @author usuario
*/
public class Conexion extends Object implements Serializable {

public static final String PROP_SAMPLE_PROPERTY = "sampleProperty";

private String sampleProperty;

private PropertyChangeSupport propertySupport;

Connection mibase;
Statement operacion;
ResultSet respuesta;
PreparedStatement comando;

private String cod;
private String curs;
private int cred;
private int horat;
private int horap;
private int horal;
private int cicl;
private int tip;






public Conexion() throws SQLException {
propertySupport = new PropertyChangeSupport(this);
try {

Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver Cargado");
mibase=DriverManager.getConnection("jdbc:oracle:th in:@localhost:1521:xe","system","sistemas");
System.out.println("Base de datos conectada");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}




public boolean insertar_curso()
{
// Vector insertar=new Vector();
boolean exito=false;

String insertar="insert into cursopp(cod_curso,nom_curso,cred_curso,hrs_teoria, hrs_pract,hrs_lab,ciclo,tipo_curso) values(?,?,?,?,?,?,?,?)";
System.out.println(insertar);

try {
comando=mibase.prepareStatement(insertar);


comando.setString(1,cod);
comando.setString(2,curs);
comando.setInt(3,cred);

comando.setInt(4,horat);
comando.setInt(5,horap);
comando.setInt(6,horal);
comando.setInt(7,cicl);
comando.setInt(8,tip);

System.out.println(comando);
System.out.println(cod);
System.out.println(curs);
System.out.println(cred);
System.out.println(horat);
System.out.println(horap);
System.out.println(horal);
System.out.println(cicl);
System.out.println(tip);

int fila=comando.executeUpdate();


System.out.println(fila);
// insertar.add(fila);
if(fila>0)
{
exito=true;

} else {
exito=false;
}
// System.out.println(exito);
comando.close();

} catch (SQLException ex) {
ex.printStackTrace();
}
//comando.close();
return exito;
}

public String getCod() {
return cod;

}

public void setCod(String cod) {
this.cod = cod;
}

public String getCurs() {
return curs;
}

public void setCurs(String curs) {
this.curs = curs;
}

public int getCred() {
return cred;
}

public void setCred(int cred) {
this.cred = cred;
}

public int getHorat() {
return horat;
}

public void setHorat(int horat) {
this.horat = horat;
}

public int getHorap() {
return horap;
}

public void setHorap(int horap) {
this.horap = horap;
}

public int getHoral() {
return horal;
}

public void setHoral(int horal) {
this.horal = horal;
}

public int getCicl() {
return cicl;
}

public void setCicl(int cicl) {
this.cicl = cicl;
}

public int getTip() {
return tip;
}

public void setTip(int tip) {
this.tip = tip;
}

}


La tabla se llama cursopp con los datos bien estructurados

codigo string
nombre string
para los demas campos integer, son 8 campos en total

cuando ejecuto la aplicacion me sale esto


true
Registro exitoso !!!
null null 0 0 0 0 0 0

quiere decir q inserta registro porq devuelve true pero los datos son nulos y voy a ver en el manejador de base de datos del netbeans al hacer la consulta me bota en codigo del curso valores correlativos(41.42, por ejem) y los demas campos null para el nombre y 0 para los campos integer, es decir me llena dos filas con correlativo para el codigo y nulo para los demas

cual esel problema
??
espero puedan ayudarme.--------------------------------------------------------
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:50.