java- How to use PreparedStatement correctly?

0

It turns out that I am trying to parameterize a querie , apparently it takes the data but returns an erroneous result for example.

Select campo from tabla where nombre ='pepito'

Does not return anything

select campo from tabla where nombre <>'jose'
**pepito**, juan,horacio

returns the distints and the same happens when I put a minor that, or greater than (in case you consult a numeric field)

str = "SELECT TABLA WHERE ? "+ operador +"?";
PreparedStatement prepstm = null;
Connection conn;
conn = DBConnector.getInstance().conect();
prepstm = conn.prepareStatement(str);
prepstm.setString(1, campo);
prepstm.setString(2, valor);
ResultSet rs = prepstm.executeQuery();      
    
asked by Enzo Zalazar 29.05.2018 в 17:07
source

0 answers