Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@ page import="banco.RequisicoesDAO" %>
- <%@ page import="classes.Requisicoes" %>
- <%@ page import="java.util.List" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>DashBoard API</title>
- </head>
- <body>
- <h1>Teste</h1>
- <%
- RequisicoesDAO dao = new RequisicoesDAO();
- List<Requisicoes> reqs = dao.getRequisicoes(0);
- for (Requisicoes req : reqs) {
- %>
- <br />
- <%=req.getCtrnro()%>,
- <%=req.getEnvio()%>:
- <%=req.getRetorno()%>
- <hr />
- <%
- }
- %>
- </body>
- </html>
- package classes;
- public class Requisicoes {
- private int unncod;
- private int ctrnro;
- private int code;
- private String envio;
- private String retorno;
- public Requisicoes() {}
- public int getCode() {
- return code;
- }
- public void setCode(int code) {
- this.code = code;
- }
- public String getEnvio() {
- return envio;
- }
- public void setEnvio(String envio) {
- this.envio = envio;
- }
- public String getRetorno() {
- return retorno;
- }
- public void setRetorno(String retorno) {
- this.retorno = retorno;
- }
- public int getUnncod() {
- return unncod;
- }
- public void setUnncod(int unncod) {
- this.unncod = unncod;
- }
- public int getCtrnro() {
- return ctrnro;
- }
- public void setCtrnro(int ctrnro) {
- this.ctrnro = ctrnro;
- }
- }
- package banco;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import classes.Requisicoes;
- public class RequisicoesDAO {
- private Connection conn;
- private PreparedStatement stmt;
- public RequisicoesDAO() throws SQLException, ClassNotFoundException {
- this.conn = DriverManager.getConnection("jdbc:mysql://DOMINIO:3306/BANCO", "USER", "SENHA");
- }
- private void conecta() throws SQLException {
- this.conn = DriverManager.getConnection("jdbc:mysql://pedidoswcargo.mysql.dbaas.com.br:3306/pedidoswcargo", "pedidoswcargo", "iconex-05");
- }
- public List<Requisicoes> getRequisicoes(int processo) throws Exception{
- List<Requisicoes> reqs = new ArrayList<Requisicoes>();
- String tabela = getTable(processo);
- String sql = "SELECT * FROM "+tabela+" WHERE data >= CURDATE()";
- System.out.println(sql);
- PreparedStatement ps = conn.prepareStatement(sql);
- ResultSet rs = ps.executeQuery();
- if (rs.next()) {
- Requisicoes req = new Requisicoes();
- if(processo == 2 ) {
- req.setUnncod(2);
- req.setCtrnro(rs.getInt("operacional"));
- int code = rs.getString("status").equals("OK") ? 200 : 500;
- req.setCode(code);
- req.setEnvio(rs.getString("jsonEnv"));
- req.setRetorno(rs.getString("jsonRet"));
- }else {
- req.setUnncod(rs.getInt("unncod"));
- req.setCtrnro(rs.getInt("ctrnro"));
- req.setCode(rs.getInt("status"));
- req.setEnvio(rs.getString("envio"));
- req.setRetorno(rs.getString("retorno"));
- }
- reqs.add(req);
- ps.close();
- }
- return reqs;
- }
- private String getTable(int processo) {
- switch(processo) {
- case 0:
- return "tableUm";
- case 1:
- return "tableDois";
- case 2:
- return "tableTres";
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement