0
Syntax SQL error on the part 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");
}
Welcome to Stackoverflow Douglas. This field
cod_rfid
tableestoque
is numerical or text? What is the exact error message that appears?– Pedro Gaspar
@Carlosheuberger, don’t you want to post your solution as an answer? If you want, explain a little more about your suggestion, to make it more complete.
– Pedro Gaspar
the cod_rfid field in the BD is as varchar and in the Java code is as String
– Douglas Costa