Query Syntax Error with RFID Code Filter

0

You're giving Syntax SQL error in from estoque where cod_rfid = 102 . Note: 102 is the value that is in the RFID tag.

    String dadoRFID = new String(readBuffer);
    String Del_inc = dadoRFID.substring(0,1); //Pega o primeiro caractere
    String Del_local = dadoRFID.substring(5,6); //Pega o primeiro caractere

    System.out.println(Del_inc); 
    System.out.println(Del_local); 

    if((Del_inc.equals("#")) && (Del_local.equals("&"))  ) { //Se caracteres OK.
        msg_rec_str = dadoRFID.substring(6, 12); //Pega os prox 6 caracteres após o "#"
        loc_est_str = dadoRFID.substring(1,5);
    }else {
        System.out.println("Não encontrou");
    }

    System.out.println("MSG"+ msg_rec_str);
    System.out.println("teste"+ loc_est_str);
    try {
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sistemarfid?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&useTimezone=true&serverTimezone=UTC", "root", "12345");
         Statement statement=con.createStatement();

         Resultset rs= (Resultset) statement.executeQuery("select from estoque where cod_rfid =" + msg_rec_str);
         ((ResultSet) rs).next();
         int codrfid = ((ResultSet) rs).getInt(3);

         Resultset rs2= (Resultset) statement.executeQuery("select from estoque where endereco_estoque =" + loc_est_str);
         ((ResultSet) rs2).next();
         int localrfid = ((ResultSet) rs2).getInt(4);

         Resultset rs3= (Resultset) statement.executeQuery("select from estoque where estatus =" + 0);
         ((ResultSet) rs3).next();
         int estatusrfid = ((ResultSet) rs3).getInt(5);

             String dado_bd = "0"+ codrfid; //Variavel com o 
             String loc = "0"+localrfid; //Var com o retorno do local do BD
             String status_bd = "0"+ estatusrfid;           

             if(loc.equals(loc_est_str)) {
               System.out.println("LOCAL CONFIRMADO");
        switch (status_bd) { //Faz buscar para trocar
        case "0":
            System.out.println("status = 1");
            String sql1 = "update estoque set estatus = 1";
            PreparedStatement stmt = con.prepareStatement(sql1);
            stmt.executeUpdate();
            //stmt.execute();
            stmt.close();

            con.close();

            break;
        case "1":
            System.out.println("status = 2");
            String sql2 = "update estoque set estatus = 1";
            PreparedStatement stmt2 = con.prepareStatement(sql2);
            stmt2.executeUpdate();
            //stmt.execute();
            stmt2.close();

            break;
        case "2":
            System.out.println("status = 1");

            String sql3 = "update estoque set estatus = 1";
            PreparedStatement stmt3 = con.prepareStatement(sql3);
            stmt3.executeUpdate();
            //stmt.execute();
            stmt3.close();

            break;
        default:System.out.println("Status nao confirmado");
            break;
        }

             }else {
               System.out.println("LOCAL ERRADO");
             }
    
asked by anonymous 06.11.2018 / 02:24

2 answers

1

In your querys you have not specified what to select.

Example: SELECT nome_coluna FROM estoque WHERE ....

    
06.11.2018 / 11:46
1

In the queries you have to inform which column you want to select. And this must be done before the "FROM". To not give the "Column Index out" error, try the following:

 "SELECT nome_tabela.nome_coluna FROM estoque WHERE cod_rfid ="
  • Use a period between the table name and the column name to specify more exactly what you want to query.

  • You have two other queries with the same error.

07.11.2018 / 03:23