Guest User

Untitled

a guest
Nov 6th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. String dadoRFID = new String(readBuffer);
  2. String Del_inc = dadoRFID.substring(0,1); //Pega o primeiro caractere
  3. String Del_local = dadoRFID.substring(5,6); //Pega o primeiro caractere
  4.  
  5. System.out.println(Del_inc);
  6. System.out.println(Del_local);
  7.  
  8. if((Del_inc.equals("#")) && (Del_local.equals("&")) ) { //Se caracteres OK.
  9. msg_rec_str = dadoRFID.substring(6, 12); //Pega os prox 6 caracteres após o "#"
  10. loc_est_str = dadoRFID.substring(1,5);
  11. }else {
  12. System.out.println("Não encontrou");
  13. }
  14.  
  15. System.out.println("MSG"+ msg_rec_str);
  16. System.out.println("teste"+ loc_est_str);
  17. try {
  18. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sistemarfid?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&useTimezone=true&serverTimezone=UTC", "root", "12345");
  19. Statement statement=con.createStatement();
  20.  
  21. Resultset rs= (Resultset) statement.executeQuery("select from estoque where cod_rfid =" + msg_rec_str);
  22. ((ResultSet) rs).next();
  23. int codrfid = ((ResultSet) rs).getInt(3);
  24.  
  25. Resultset rs2= (Resultset) statement.executeQuery("select from estoque where endereco_estoque =" + loc_est_str);
  26. ((ResultSet) rs2).next();
  27. int localrfid = ((ResultSet) rs2).getInt(4);
  28.  
  29. Resultset rs3= (Resultset) statement.executeQuery("select from estoque where estatus =" + 0);
  30. ((ResultSet) rs3).next();
  31. int estatusrfid = ((ResultSet) rs3).getInt(5);
  32.  
  33. String dado_bd = "0"+ codrfid; //Variavel com o
  34. String loc = "0"+localrfid; //Var com o retorno do local do BD
  35. String status_bd = "0"+ estatusrfid;
  36.  
  37. if(loc.equals(loc_est_str)) {
  38. System.out.println("LOCAL CONFIRMADO");
  39. switch (status_bd) { //Faz buscar para trocar
  40. case "0":
  41. System.out.println("status = 1");
  42. String sql1 = "update estoque set estatus = 1";
  43. PreparedStatement stmt = con.prepareStatement(sql1);
  44. stmt.executeUpdate();
  45. //stmt.execute();
  46. stmt.close();
  47.  
  48. con.close();
  49.  
  50. break;
  51. case "1":
  52. System.out.println("status = 2");
  53. String sql2 = "update estoque set estatus = 1";
  54. PreparedStatement stmt2 = con.prepareStatement(sql2);
  55. stmt2.executeUpdate();
  56. //stmt.execute();
  57. stmt2.close();
  58.  
  59. break;
  60. case "2":
  61. System.out.println("status = 1");
  62.  
  63. String sql3 = "update estoque set estatus = 1";
  64. PreparedStatement stmt3 = con.prepareStatement(sql3);
  65. stmt3.executeUpdate();
  66. //stmt.execute();
  67. stmt3.close();
  68.  
  69. break;
  70. default:System.out.println("Status nao confirmado");
  71. break;
  72. }
  73.  
  74. }else {
  75. System.out.println("LOCAL ERRADO");
  76. }
Add Comment
Please, Sign In to add comment