You are on page 1of 21

Mster Internacional en Software

Libre - Bases de Datos

Ejercicio 5 Integracin con PHP y Java(25%)


a)
Realizar un programa en PHP (utilizando el SGBD PostgreSQL) que permita introducir los
siguientes datos a las tablas creadas en los ejercicios anteriores:
Numero regimiento.
Numero batalln.
Fecha
ID Tipo comida
ID Momento comida
Numero soldados
Una vez introducidos los datos y pulsar sobre un botn Insertar, se verificar la correccin de
los datos, enseando el nombre del regimiento, el nombre del batalln, la descripcin del tipo
de comida y del momento de la comida.
Una vez comprobados los datos tendremos habr opcin de pulsar sobre Continuar. En el
caso de haber algn dato incorrecto tendremos opcin de volver a la pantalla anterior.
La siguiente pantalla servir para pedir los datos:
Id alimento
Cantidad
De forma continuada, hasta introducir en id alimento un cero. Cada vez que aceptemos los
datos deber aparecer en pantalla la descripcin del alimento.
Al finalizar el proceso, por haber introducido un cero en id alimento, se nos mostrar el total de
caloras y protenas que aportar a cada soldado el men creado.
NOTA: Para traspasar el contenido de una variable de un programa PHP a otro que se llame,
sin necesidad de que el valor sea de un campo recin introducido por el usuario, se puede
utilizar el cdigo:
<input type="hidden" name="idcomida" value="<?php echo $NumeroComida; ?> ">

Mster Internacional en Software


Libre - Bases de Datos
La secuencia de funcionamiento ser:

error

Mster Internacional en Software


Libre - Bases de Datos
Pegad aqu el cdigo PHP:
autentica.php
<html>
<head>
<title>Control Dieta Batallon</title>
</head>
<body>
<center><h1>Control Dieta</h1></center>
<form action="control.php" method="post">
<table align="center" width="225" cellspacing="2" cellpadding="2" border="0">
<tr>
<td colspan="2" align="center" bgcolor=#cccccc>Introduce nombre de usuario</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="right">USER: </td>
<td><input type="Text" name="user" size="14" maxlength="50"></td>
</tr>
<tr>
<td align="right">PASSWORD: </td>
<td><input type="password" name="password" size="14" maxlength="50"></td>
</tr>
<tr>
<BR>
<td colspan="2" align="center"><input type="Submit" value="Entrar"></td>
</tr>
</table>
</form>
</body>
</html>

control.php
<html>
<head>
<title>Control de Acceso</title>
</head>
<body>
<br>
<?php
$conexio = pg_connect("host=localhost port=5432 dbname=ranbuntun user=postgres
password=marlon1973");

if (!$conexio)
{
die("Could not open connection to database server");
}
$sql = "SELECT COUNT(*) FROM client WHERE nick = '".$_POST['user']."' AND
password = '".$_POST['password']."'";
$resultat_set = pg_Exec ($conexio, $sql);

Mster Internacional en Software


Libre - Bases de Datos
$TotalRegistres = pg_result($resultat_set, 0);
pg_close($conexio);
if ($TotalRegistres == 0) {
echo "Autentication Error: ";
?> <a href="autentica.php">Back to home</a>
<?php
}
else {
header("location: captura.php");
}
?>
</body>
</html>

captura.php
<html>
<head>
<title>Control Dieta Ejercito</title>
</head>
<body>
<center><h1>Introduccion Datos</h1></center>
<form action="verifica.php" method="post">
<table align="center" width="250" cellspacing="2" cellpadding="2" border="0">
<tr>
<td colspan="2" align="center" bgcolor=#cccccc>Operation details</td>
</tr>
<tr>
<td align="right">Numero de Regimiento: </td>
<td><input type="Text" name="id" size="14" maxlength="50"></td>
</tr>
<tr>
<td align="right">Numero de Batallon: </td>
<td><input type="Text" name="id_reg" size="14" maxlength="50"></td>
</tr>
<tr>
<td align="right">Fecha: </td>
<td><input type="Text" name="fechapedido" size="14" maxlength="50"></td>
</tr>
<tr>
<td align="right">Id. Tipo de Comida: </td>
<td><input type="Text" name="tipocomida" size="14" maxlength="50"></td>
</tr>
<tr>
<td align="right">Id. Momento Comida: </td>
<td><input type="Text" name="nombremomento" size="14" maxlength="50"></td>
</tr>
<tr>
<td align="right">Numero de Soldados: </td>
<td><input type="Text" name="integrantes" size="14" maxlength="50"></td>

Mster Internacional en Software


Libre - Bases de Datos
</tr>
<tr>
<BR>
<td colspan="2" align="center"><input type="Submit" value="Entrar"></td>
</tr>
</table>
</form>
</body>
</html>

verifica.php
<html>
<head>
<title>Control Dieta</title>
</head>
<body>
<br>
<center><h1>Control dieta ejercito</h1></center>
<form action="componentes.php" method="post">
<?php
$conexio = pg_connect("host=localhost port=5432 dbname=ranbuntun password=marlon1973
user=postgres") or die("<BR>ERROR open BD!<BR>");
// Retrieve ticket id from short nom
$sql_1 = "SELECT nombrereg FROM regimiento WHERE id = '".$_POST['id']."'";
$result_set_1 = pg_Exec ($conexio, $sql_1);
$numRows_1 = pg_num_rows ($result_set_1);
if ($numRows_1 == 0) {
$nomreg="Regimiento no encontrado";
}
else
{
$nomreg=pg_result($result_set_1, 0);
}
$sql_2 = "SELECT nombre FROM batallon WHERE id_b = '".$_POST['id_bat']."'";
$result_set_2 = pg_Exec ($conexio, $sql_2);
$numRows_2 = pg_num_rows ($result_set_2);
if ($numRows_2 == 0) {
$nombat="Batallon no encontrado";
}
else
{
$nombat=pg_result($result_set_2, 0);
}
$sql_3 = "SELECT nombremomento FROM mision WHERE id = '".$_POST['tipocomida']."'";
$result_set_3 = pg_Exec ($conexio, $sql_3);
$numRows_3 = pg_num_rows ($result_set_3);

Mster Internacional en Software


Libre - Bases de Datos
if ($numRows_3 == 0) {
$nomcom="Tipo de comida no encontrada";
}
else
{
$nomcom=pg_result($result_set_3, 0);
}
$sql_4 = "SELECT tipocomida FROM orden WHERE id_orden = '".$_POST['nombremomento']."'";
$result_set_4 = pg_Exec ($conexio, $sql_4);
$numRows_4 = pg_num_rows ($result_set_4);
if ($numRows_4 == 0) {
$nommom="Tipo de comida no encontrada";
}
else
{
$nommom=pg_result($result_set_4, 0);
}
pg_close($conexio);
?>
<table align="center" width="450" cellspacing="2" cellpadding="2" border="0">
<tr>
<td colspan="2" align="center" bgcolor=#cccccc>Datos Introducidos</td>
</tr>
<tr>
<td align="right">Regimiento: </td>
<td><?php echo $nomreg ?></td>
</tr>
<tr>
<td align="right">Batallon: </td>
<td><?php echo $nombat ?></td>
</tr>
<tr>
<td align="right">Tipo Comida: </td>
<td><?php echo $nomcom ?></td>
</tr>
<tr>
<td align="right">Momento Comida: </td>
<td><?php echo $nommom ?></td>
</tr>
<tr>
<BR>
<td colspan="2" align="center"><input type="Submit" value="Introducir Componentes"></td>
</tr>
</body>
</html>

Mster Internacional en Software


Libre - Bases de Datos
componentes.php
<html>
<head>
<title>Control Dieta Ejercito</title>
</head>
<body>
<center><h1>Introduccion Componentes Comidas</h1></center>
<form action="introducecomponente.php" method="post">
<table align="center" width="250" cellspacing="2" cellpadding="2" border="0">
<tr>
<td colspan="2" align="center" bgcolor=#cccccc>Operation details</td>
</tr>
<tr>
<td align="right">ID del Alimento: </td>
<td><input type="Text" name="id" size="14" maxlength="50"></td>
</tr>
<tr>
<td align="right">Cantidad: </td>
<td><input type="Text" name="cantidad" size="14" maxlength="50"></td>
</tr>
<tr>
<BR>
<td colspan="2" align="center"><input type="Submit" value="Entrar"></td>
</tr>
</table>
</form>
</body>
</html>
introducecomponentes.php
<html>
<head>
<title>Control Dieta</title>
</head>
<body>
<br>
<center><h1>Control dieta ejercito</h1></center>
<form action="componentes.php" method="post">
<?php
$conexio = pg_connect("host=localhost port=5432 dbname=ranbuntun password=marlon1973
user=postgres") or die("<BR>ERROR open BD!<BR>");
// Retrieve ticket id from short nom
$sql_1 = "SELECT alimento FROM alimento WHERE id = '".$_POST['id']."'";
$result_set_1 = pg_Exec ($conexio, $sql_1);
$numRows_1 = pg_num_rows ($result_set_1);
if ($numRows_1 == 0) {
$nomreg="Regimiento no encontrado";
}
else

Mster Internacional en Software


Libre - Bases de Datos
{
$nomreg=pg_result($result_set_1, 0);
}
$sql_2 = "SELECT calorias FROM alimento WHERE id = '".$_POST['id']."'";
$result_set_2 = pg_Exec ($conexio, $sql_2);
$numRows_2 = pg_num_rows ($result_set_2);
if ($numRows_2 == 0) {
}
$sql_3 = "SELECT id_menu FROM menu WHERE id = '".$_POST['tipocomida']."'";
$result_set_3 = pg_Exec ($conexio, $sql_3);
$numRows_3 = pg_num_rows ($result_set_3);
{
$menu=pg_result($result_set_1, 1);
$totalcal=$calorias*$integrantes;
$sql_4 = "SELECT proteinas FROM alimento WHERE id = '".$_POST['id']."'";
$result_set_4 = pg_Exec ($conexio, $sql_2);
$numRows_4 = pg_num_rows ($result_set_2);
if ($numRows_4 == 0) {
$sql_2 = "SELECT proteinas FROM alimento WHERE id = '".$_POST['id']."'";
$result_set_4 = pg_Exec ($conexio, $sql_4);
$numRows_4 = pg_num_rows ($result_set_4);
if ($numRows_4 == 0) {
}
{
$proteinas=pg_result($result_set_5, 0);
$sql_5 = "SELECT id_menu FROM menu WHERE id = '".$_POST['tipocomida']."'";
$result_set_5 = pg_Exec ($conexio, $sql_5);
$numRows_5 = pg_num_rows ($result_set_5);
{
$menu=pg_result($result_set_1, 1);
$totalpro=$proteinas*$integrantes;
}
pg_close($conexio);
?>
<table align="center" width="450" cellspacing="2" cellpadding="2" border="0">
<tr>
<td colspan="2" align="center" bgcolor=#cccccc>Datos Introducidos</td>
</tr>
<tr>
<td align="right">alimento: </td>
<td><?php echo $nomreg ?></td>
</tr>
<td align="right">Total Calorias por Soldado: </td>
<td><?php echo $calorias ?></td>
</tr>
<tr>

Mster Internacional en Software


Libre - Bases de Datos
<td align="right">Total Proteinas por Soldado: </td>
<td><?php echo $proteinas ?></td>
<tr>
<td align="right">Total Proteinas por Soldado: </td>
<td><?php echo $totalcal ?></td>
<BR>
<tr>
<td align="right">Total Calorias por Soldado: </td>
<td><?php echo $totalpro ?></td>
<BR>
<td colspan="2" align="center"><input type="Submit" value="Introducir Mas Componentes"></td>
</tr>
</body>
</html>

Adjuntar las capturas de pantalla que consideris necesarias para mostrar el correcto
funcionamiento de la aplicacin:
Ingreso a la aplicacion

Control Dieta

Mster Internacional en Software


Libre - Bases de Datos

Detecta Error

Introduccir componentes

Busqueda datos correcto

10

Mster Internacional en Software


Libre - Bases de Datos
b)
Realizar un programa en java (utilizando el SGBD PostgreSQL) que muestre los datos
nutricionales de los alimentos usados en la ltima comida. El programa deber funcionar
ininterrumpidamente, mostrando cada 2 minutos los datos de los componentes del ltimo men
creado. Se pide concretamente que se muestre el nombre del alimento, las caloras, las
protenas y las grasas de cada uno de los mismos.
ConexionBd.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package utilidades;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Kevin Arnold
*/
public class ConexionDB {
public static Connection GetConnection()
{
String servidor;
Connection conexion=null;
try
{
Class.forName("org.postgresql.Driver");
servidor = "jdbc:postgresql://localhost:5432/catalogo";
String usuarioDB="postgres";
String passwordDB="admin";
conexion= DriverManager.getConnection(servidor,usuarioDB,passwordDB);
}
catch(ClassNotFoundException ex)
{
System.out.println("error en la conexion con la base de datos");
conexion=null;
}
catch(SQLException ex)
{
System.out.println("error2 en la conexion con la base de datos");
conexion=null;
}
catch(Exception ex)
{
System.out.println("error3 en la conexion con la base de datos");
conexion=null;
}
finally
{
return conexion;

11

Mster Internacional en Software


Libre - Bases de Datos
}
}
}
Componentemenu.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package utilidades;
/**
*
* @author programador
*/
public class ComponenteMenu {
private String alimento,calorias,proteinas,grasa;
public ComponenteMenu() {
}
public String getGrasa() {
return grasa;
}
public void setGrasa(String grasa) {
this.grasa = grasa;
}
public String getAlimento() {
return alimento;
}
public void setAlimento(String alimento) {
this.alimento = alimento;
}
public String getCalorias() {
return calorias;
}
public void setCalorias(String calorias) {
this.calorias = calorias;
}
public String getProteinas() {
return proteinas;
}
public void setProteinas(String proteinas) {
this.proteinas = proteinas;
}
}
Controldieta.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates

12

Mster Internacional en Software


Libre - Bases de Datos
* and open the template in the editor.
*/
package utilidades;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
/**
*
* @author programador
*/
@ManagedBean
@SessionScoped
public class ControlDieta {
/**
* Creates a new instance of ControlDieta
*/
private String regimiento,regimiento2;
private String batallon,batallon2;
private String fecha;
private String tpComida,tipComida2;
private String momentoComida,momentoComida2;
private String numSoldado,alimento;
private int proteinas,calorias,idAlimento,cantidad,conceMenu;
private float caloriaXsoldado,proteinasXsoldado,sumCalorias,sumProteinas;
private List<ComponenteMenu> lcm = new ArrayList<>();
public ControlDieta() {
calorias=0;proteinas=0;
}
public List<ComponenteMenu> getLcm() {
return lcm;
}
public void setLcm(List<ComponenteMenu> lcm) {
this.lcm = lcm;
}
public float getCaloriaXsoldado() {
return caloriaXsoldado;
}
public void setCaloriaXsoldado(float caloriaXsoldado) {
this.caloriaXsoldado = caloriaXsoldado;
}
public float getProteinasXsoldado() {
return proteinasXsoldado;
}
public void setProteinasXsoldado(float proteinasXsoldado) {
this.proteinasXsoldado = proteinasXsoldado;
}

13

Mster Internacional en Software


Libre - Bases de Datos
public float getSumCalorias() {
return sumCalorias;
}
public void setSumCalorias(float sumCalorias) {
this.sumCalorias = sumCalorias;
}
public float getSumProteinas() {
return sumProteinas;
}
public void setSumProteinas(float sumProteinas) {
this.sumProteinas = sumProteinas;
}

public String getAlimento() {


return alimento;
}
public void setAlimento(String alimento) {
this.alimento = alimento;
}
public int getCantidad() {
return cantidad;
}
public void setCantidad(int cantidad) {
this.cantidad = cantidad;
}
public int getProteinas() {
return proteinas;
}
public void setProteinas(int proteinas) {
this.proteinas = proteinas;
}
public int getCalorias() {
return calorias;
}
public void setCalorias(int calorias) {
this.calorias = calorias;
}
public int getIdAlimento() {
return idAlimento;
}
public void setIdAlimento(int idAlimento) {
this.idAlimento = idAlimento;
}
public String getMomentoComida2() {
return momentoComida2;
}

14

Mster Internacional en Software


Libre - Bases de Datos
public void setMomentoComida2(String momentoComida2) {
this.momentoComida2 = momentoComida2;
}
public String getTipComida2() {
return tipComida2;
}
public void setTipComida2(String tipComida2) {
this.tipComida2 = tipComida2;
}
public String getBatallon2() {
return batallon2;
}
public void setBatallon2(String batallon2) {
this.batallon2 = batallon2;
}

public String getRegimiento2() {


return regimiento2;
}
public void setRegimiento2(String regimiento2) {
this.regimiento2 = regimiento2;
}
public String getRegimiento() {
return regimiento;
}
public void setRegimiento(String regimiento) {
this.regimiento = regimiento;
}
public String getBatallon() {
return batallon;
}
public void setBatallon(String batallon) {
this.batallon = batallon;
}
public String getFecha() {
return fecha;
}
public void setFecha(String fecha) {
this.fecha = fecha;
}
public String getTpComida() {
return tpComida;
}
public void setTpComida(String tpComida) {
this.tpComida = tpComida;
}

15

Mster Internacional en Software


Libre - Bases de Datos
public String getMomentoComida() {
return momentoComida;
}
public void setMomentoComida(String momentoComida) {
this.momentoComida = momentoComida;
}
public String getNumSoldado() {
return numSoldado;
}
public void setNumSoldado(String numSoldado) {
this.numSoldado = numSoldado;
}
public String comprobarDieta() throws SQLException{
regimiento2="";batallon2="";tipComida2="";momentoComida2="";
int rs1=0,concecutivo=0;
Connection c;
String StrQuery;
c = ConexionDB.GetConnection();
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
if (c != null) {
try {
StrQuery = " select * from regimiento where id='" + regimiento.trim() + "'";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(StrQuery);
if (rs.next()) {
regimiento2=rs.getString(2);
//c.close();
}
} catch (SQLException ex) {
Logger.getLogger(ControlDieta.class.getName()).log(Level.SEVERE, null, ex);
}
try {
StrQuery = "SELECT * FROM batallon where id_b='" + batallon.trim() + "'";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(StrQuery);
if (rs.next()) {
batallon2=rs.getString(4);
//c.close();
}
} catch (SQLException ex) {
Logger.getLogger(ControlDieta.class.getName()).log(Level.SEVERE, null, ex);
}
try {
StrQuery = "select * from alimento where id_a='" + tpComida.trim() + "'";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(StrQuery);
if (rs.next()) {
tipComida2=rs.getString(5);
//c.close();
}
} catch (SQLException ex) {
Logger.getLogger(ControlDieta.class.getName()).log(Level.SEVERE, null, ex);
}

16

Mster Internacional en Software


Libre - Bases de Datos
try {
StrQuery = "select * from comida where idcomida='" + momentoComida.trim() + "'";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(StrQuery);
if (rs.next()) {
momentoComida2=rs.getString(3);
//c.close();
}
} catch (SQLException ex) {
Logger.getLogger(ControlDieta.class.getName()).log(Level.SEVERE, null, ex);
}
c.close();rs.close();stmt.close();
}
if(regimiento2.isEmpty() || batallon2.isEmpty() || tipComida2.isEmpty() || momentoComida2.isEmpty()){
if(regimiento2.isEmpty()){
regimiento2="No se Encontro Regimiento";
}
if(batallon2.isEmpty()){
batallon2="No se Encontro Batallon";
}
if(tipComida2.isEmpty()){
tipComida2="No se Encontro Tipo Comida";
}
if(momentoComida2.isEmpty()){
momentoComida2="No se Encontro Momento de la Comida";
}
return "buscarDatos_1.xhtml";
}else{
c = ConexionDB.GetConnection();int conce=1;
if (c != null) {
StrQuery = "select max(idmenu) FROM menu";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(StrQuery);
if(rs.next()){
concecutivo=Integer.parseInt(rs.getString(1));
conce=concecutivo+1;
conceMenu=conce;
}
StrQuery
=
"insert
into
menu(idMenu,idTipoComida,idMomentoComida,fecha)
values('"+conce+"','"+tpComida+"','"+momentoComida+"','"+fecha+"')";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs1 = stmt.executeUpdate(StrQuery);
if(rs1>0){
System.out.println("inserto");
c.close();stmt.close();
}else{
System.out.println("no inserto");
}
}
return "buscarDatos.xhtml";
}
}
public String buscaPagcomponente(){

17

Mster Internacional en Software


Libre - Bases de Datos
return "componente.xhtml";
}
public String sumarAlimentos(){
int conce = 0,concecutivo;
Connection c;
String StrQuery;
c = ConexionDB.GetConnection();
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
if (c != null) {
try {
StrQuery = "SELECT alimento,calorias, proteinas FROM alimento where id_a='" + idAlimento + "'";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(StrQuery);
if (rs.next()) {
alimento=rs.getString(1);
calorias=Integer.parseInt(rs.getString(2));
proteinas=Integer.parseInt(rs.getString(3));
if(idAlimento!=0){
//aqui s insertan los componentes del menu
StrQuery = "select max(idcommenu) FROM componenteMenu";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(StrQuery);
if(rs.next()){
if(rs.getString(1)!=null){
concecutivo=Integer.parseInt(rs.getString(1));
conce=concecutivo+1;
}else{
conce=1;
}
}
StrQuery
=
"insert
into
componenteMenu(idcommenu,idmenu,idalimento)
values('"+conce+"','"+conceMenu+"','"+idAlimento+"')";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
int rs5=stmt.executeUpdate(StrQuery);
if(rs5>0){
System.out.println("inserto????? componenteMenu");
}else{
System.out.println("No *****inserto componenteMenu");
}
sumCalorias=sumCalorias+calorias*cantidad;
sumProteinas=sumProteinas+proteinas*cantidad;
}
//c.close();
}
c.close();stmt.close();rs.close();
} catch (SQLException ex) {
Logger.getLogger(ControlDieta.class.getName()).log(Level.SEVERE, null, ex);
}
}
if(idAlimento==0){
caloriaXsoldado=sumCalorias/Integer.parseInt(numSoldado);
proteinasXsoldado=sumProteinas/Integer.parseInt(numSoldado);
return "total.xhtml";
}else{
return "introducirMasComponente.xhtml";
}
}

18

Mster Internacional en Software


Libre - Bases de Datos
public String compMenu(){
int rs1,conce=1,idMenu = 0;List<String> lis = new ArrayList<>();
Connection c;
String StrQuery;
c = ConexionDB.GetConnection();
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
if (c != null) {
try {
//aqui se debe insertar en el menu
StrQuery = "SELECT idmenu\n" +
" FROM menu as m order by idmenu asc";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(StrQuery);
System.out.println("tamao");
while(rs.next()){
idMenu=Integer.parseInt(rs.getString(1));
System.out.println("dele--"+rs.getString(1));
}
System.out.println("!!!!!!!"+idMenu);
StrQuery = "select distinct idAlimento from componenteMenu where idmenu="+idMenu+"";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(StrQuery);
while(rs.next()){
System.out.println("mico");
//
lis.add(rs.getString(1));
StrQuery = "SELECT alimento,calorias, proteinas, grasas FROM alimento where id_a='" +
rs.getString(1) + "'";
stmt
=
c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(StrQuery);
if(rs.next()){
ComponenteMenu d = new ComponenteMenu();
d.setAlimento(rs.getString(1));
d.setCalorias(rs.getString(2));
d.setProteinas(rs.getString(3));
d.setGrasa(rs.getString(4));
lcm.add(d);
}
}
//
for(String x:lis){
////
ComponenteMenu d = new ComponenteMenu();
////
d.set
//
System.out.println("xxxxxx---"+x);
//
StrQuery = "SELECT alimento,calorias, proteinas, grasas FROM alimento where id_a='" + x + "'";
//
stmt = c.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
//
rs = stmt.executeQuery(StrQuery);
//
if(rs.next()){
//
ComponenteMenu d = new ComponenteMenu();
//
d.setAlimento(rs.getString(1));
//
d.setCalorias(rs.getString(2));
//
d.setProteinas(rs.getString(3));
//
d.setGrasa(rs.getString(4));
//
lcm.add(d);
//
}
//
//
}
c.close();rs.close();stmt.close();

19

Mster Internacional en Software


Libre - Bases de Datos
} catch (SQLException ex) {
Logger.getLogger(ControlDieta.class.getName()).log(Level.SEVERE, null, ex);
}
}
return "reporte.xhtml";
}
public String borrar(){
lcm.clear();
return "index.xhtml";
}
}

20

Mster Internacional en Software


Libre - Bases de Datos
Formato de entrega
Se debern entregar tres ficheros:
Documento ODT, DOC, RTF o SXW del enunciado con las respuestas de los ejercicios
y el cdigo sql/java/php insertado en el mismo.
El fichero PDF resultante de convertir el fichero anterior (ODT, DOC, ...) a dicho
formato (servir para evitar posibles problemas con la insercin de imgenes y
similares).
Fichero ZIP o RAR con los programa PHP y java.
Los nombres de los ficheros debern seguir el siguiente formato:
BD_PR_Apellido1_Nombre.extensin
Asegurad de incluir vuestro nombre en el lugar previsto de la primera pgina de la PR.
Los ficheros de entregarn directamente al correo del consultor: iplana@uoc.edu
La fecha de entrega mxima son las 23h 59 minutos del 25/06/2015

21

You might also like