I do a function to verify if a plate exists in a table: 0 if it does not exist and 1 if it was found.
However, I do not understand why I still know that there is, when I only have one record in the table
public int buscarplaca(String placa){
int enco=0;
Connection cn = sql.Conectar();
ResultSet rs=null;
System.out.println(enco);
String query= "select * from cliente_mensual where placa = '"+placa+"'";
try {
System.out.println(enco);
rs = sql.stmt.executeQuery(query);
rs.first();
if(rs!=null){
enco=1;
System.out.println(enco);
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,ex);
System.out.println(enco);
return enco;
}
System.out.println(enco);
return enco;
}
I enter a data that is not, but also returns 1.
The System.Out.Println
are to verify what happens with enco
.