<%@ page import="java.sql.*" %> <%@ page import="java.util.*" %> NutriWay - Pesquisa de Alimentos

Top 10: Alimentos que contenham uma quantidade de ( Valor por 100 gs )

<%! //Variáveis de gerenciamento do banco de dados Connection Conexao; Statement stmt; ResultSet rc; // Variáveis de Data String dia, mes, SQL, Data=""; // Variáveis de campos hidden String acao, nutriente, cboordemindex, cboordemvalue, cbonutindex, cbonutvalue, texto, numerofinal, literal, valor=""; //Metodos para receber os dados do formulário public void AtualParam( HttpServletRequest Req){ try{ acao = Req.getParameter("acao"); nutriente = Req.getParameter("nutriente"); cboordemindex = Req.getParameter("cboordemindex"); cboordemvalue = Req.getParameter("cboordemvalue"); cbonutindex = Req.getParameter("cbonutindex"); cbonutvalue = Req.getParameter("cbonutvalue"); }catch(Exception e){ System.out.println("Erro leitura de parâmetros"); e.printStackTrace(); } } %> <% //Configuração dos parâmetros para conexão da base de dados Conexao = Conectar.AbreConexao(); if(Conexao == null){ System.out.println("Conexão is null!" ); Conectar.FechaConexao(Conexao); %> <% } // Confirma a criação de uma variável de conexão stmt = Conexao.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); %> <% AtualParam(request); if (acao == null ) { //cbonutvalue = "ENERG_KCAL"; SQL = "select SHRT_DESC, ENERG_KCAL FROM ndb ORDER by ENERG_KCAL desc"; }else if (acao.equals("c")) { //cbonutvalue = nutriente; SQL = "select SHRT_DESC, " +nutriente+ " FROM ndb ORDER by "+nutriente+" " + cboordemvalue; } %> <% if (nutriente == null) { nutriente = "ENERG_KCAL"; } if (nutriente.equals("WATER") ) { literal = "(g)"; } if (nutriente.equals("CALCIUM") ) { literal = "(mg)"; } if (nutriente.equals("ENERG_KCAL") ) { literal = "(kcal)"; } if (nutriente.equals("CARBOHYDRT") ) { literal = "(g)"; } if (nutriente.equals("ASH") ) { literal = "(g)"; } if (nutriente.equals("COPPER") ) { literal = "(mg)"; } if (nutriente.equals("CHOLESTRL") ) { literal = "(mg)"; } if (nutriente.equals("IRON") ) { literal = "(mg)"; } if (nutriente.equals("FIBER_TD") ) { literal = "(g)"; } if (nutriente.equals("FOLATE") ) { literal = "(mcg)"; } %> <% if (nutriente.equals("PHOSPHORUS") ) { literal = "(mg)"; } if (nutriente.equals("FA_MONO") ) { literal = "(g)"; } if (nutriente.equals("FA_POLY") ) { literal = "(g)"; } if (nutriente.equals("FA_SAT") ) { literal = "(g)"; } if (nutriente.equals("FAT") ) { literal = "(g)"; } if (nutriente.equals("MAGNESIUM") ) { literal = "(mg)"; } if (nutriente.equals("MANGANESE") ) { literal = "(mg)"; } if (nutriente.equals("NIACIN") ) { literal = "(mg)"; } if (nutriente.equals("PANTO_ACID") ) { literal = "(mg)"; } if (nutriente.equals("POTASSIUM") ) { literal = "(mg)"; } if (nutriente.equals("PROTEIN") ) { literal = "(g)"; } if (nutriente.equals("Riboflavin") ) { literal = "(mg)"; } %> <% if (nutriente.equals("SODIUM") ) { literal = "(mg)"; } if (nutriente.equals("SELENIUM") ) { literal = "(mcg)"; } if (nutriente.equals("THIAMIN") ) { literal = "(mg)"; } if (nutriente.equals("Vit_A") ) { literal = "(UI)"; } if (nutriente.equals("Vit_B12") ) { literal = "(mcg)"; } if (nutriente.equals("Vit_B6") ) { literal = "(mg)"; } if (nutriente.equals("Vit_C") ) { literal = "(mg)"; } if (nutriente.equals("ZINC") ) { literal = "(mg)"; } if (nutriente.equals("null") ) { literal = ""; } %> <% int lidos=0; try { rc = stmt.executeQuery(SQL); while(rc.next() ) { lidos++; if (lidos > 10) { return; } texto = String.valueOf(rc.getDouble(nutriente)); //texto = String.valueOf(rc.getDouble("ENERG_KCAL")); int tamanho = texto.length(); int ponto = texto.indexOf('.'); int decimal = ponto + 3; if (ponto == -1) { decimal = ponto + 2; } %> <% if (decimal >= tamanho) { decimal = tamanho; } numerofinal = texto.substring(0,decimal); //String to double : double valor = Double.valueOf(numerofinal).doubleValue(); if (valor < 0) { valor = 0.00; } %> <% if (lidos == 10) { %> <% break; } } %> <% } catch ( SQLException sqle ) { String msg = "Erro : " + sqle.getMessage(); System.out.println("Catch = " + msg ); throw new Exception(msg); } finally { if(stmt != null) { stmt.close(); } Conectar.FechaConexao(Conexao); } %>

Alimento

<%= nutriente %>  <%= literal %>

<%=rc.getString("SHRT_DESC")%>

<%=valor%>