Advertisement
Guest User

Untitled

a guest
Dec 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ page import="banco.RequisicoesDAO" %>
  4. <%@ page import="classes.Requisicoes" %>
  5. <%@ page import="java.util.List" %>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>DashBoard API</title>
  11. </head>
  12. <body>
  13. <h1>Teste</h1>
  14. <%
  15. RequisicoesDAO dao = new RequisicoesDAO();
  16. List<Requisicoes> reqs = dao.getRequisicoes(0);
  17.  
  18. for (Requisicoes req : reqs) {
  19. %>
  20. <br />
  21. <%=req.getCtrnro()%>,
  22. <%=req.getEnvio()%>:
  23. <%=req.getRetorno()%>
  24. <hr />
  25. <%
  26. }
  27. %>
  28. </body>
  29. </html>
  30.  
  31. package classes;
  32.  
  33. public class Requisicoes {
  34.  
  35. private int unncod;
  36. private int ctrnro;
  37.  
  38. private int code;
  39. private String envio;
  40. private String retorno;
  41.  
  42. public Requisicoes() {}
  43.  
  44. public int getCode() {
  45. return code;
  46. }
  47. public void setCode(int code) {
  48. this.code = code;
  49. }
  50. public String getEnvio() {
  51. return envio;
  52. }
  53. public void setEnvio(String envio) {
  54. this.envio = envio;
  55. }
  56. public String getRetorno() {
  57. return retorno;
  58. }
  59. public void setRetorno(String retorno) {
  60. this.retorno = retorno;
  61. }
  62.  
  63. public int getUnncod() {
  64. return unncod;
  65. }
  66.  
  67. public void setUnncod(int unncod) {
  68. this.unncod = unncod;
  69. }
  70.  
  71. public int getCtrnro() {
  72. return ctrnro;
  73. }
  74.  
  75. public void setCtrnro(int ctrnro) {
  76. this.ctrnro = ctrnro;
  77. }
  78. }
  79.  
  80. package banco;
  81.  
  82. import java.sql.Connection;
  83. import java.sql.DriverManager;
  84. import java.sql.PreparedStatement;
  85. import java.sql.ResultSet;
  86. import java.sql.SQLException;
  87. import java.util.ArrayList;
  88. import java.util.List;
  89. import classes.Requisicoes;
  90.  
  91.  
  92. public class RequisicoesDAO {
  93. private Connection conn;
  94. private PreparedStatement stmt;
  95.  
  96. public RequisicoesDAO() throws SQLException, ClassNotFoundException {
  97. this.conn = DriverManager.getConnection("jdbc:mysql://DOMINIO:3306/BANCO", "USER", "SENHA");
  98. }
  99.  
  100. private void conecta() throws SQLException {
  101. this.conn = DriverManager.getConnection("jdbc:mysql://pedidoswcargo.mysql.dbaas.com.br:3306/pedidoswcargo", "pedidoswcargo", "iconex-05");
  102. }
  103.  
  104. public List<Requisicoes> getRequisicoes(int processo) throws Exception{
  105. List<Requisicoes> reqs = new ArrayList<Requisicoes>();
  106. String tabela = getTable(processo);
  107. String sql = "SELECT * FROM "+tabela+" WHERE data >= CURDATE()";
  108. System.out.println(sql);
  109.  
  110.  
  111. PreparedStatement ps = conn.prepareStatement(sql);
  112. ResultSet rs = ps.executeQuery();
  113.  
  114. if (rs.next()) {
  115. Requisicoes req = new Requisicoes();
  116. if(processo == 2 ) {
  117. req.setUnncod(2);
  118. req.setCtrnro(rs.getInt("operacional"));
  119. int code = rs.getString("status").equals("OK") ? 200 : 500;
  120. req.setCode(code);
  121. req.setEnvio(rs.getString("jsonEnv"));
  122. req.setRetorno(rs.getString("jsonRet"));
  123. }else {
  124. req.setUnncod(rs.getInt("unncod"));
  125. req.setCtrnro(rs.getInt("ctrnro"));
  126. req.setCode(rs.getInt("status"));
  127. req.setEnvio(rs.getString("envio"));
  128. req.setRetorno(rs.getString("retorno"));
  129. }
  130.  
  131. reqs.add(req);
  132. ps.close();
  133.  
  134. }
  135. return reqs;
  136. }
  137.  
  138. private String getTable(int processo) {
  139. switch(processo) {
  140. case 0:
  141. return "tableUm";
  142. case 1:
  143. return "tableDois";
  144. case 2:
  145. return "tableTres";
  146. }
  147.  
  148. return null;
  149. }
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement