java - Use placeholders to search in postgresql -


i want search in table title containing substring (in case substring title passed getbookfortitle method). problem doesn't return anything.

public void getbookfortitle(string title) {             preparedstatement stm = null;             resultset rs = null;     try {                 stm = connection.preparestatement("select * books name '%?%'; ");                 rs = stm.executequery();                 while (rs.next()) {                     system.out.print(rs.getint(1));                     system.out.print(": ");                     system.out.print(rs.getstring(1));                     system.out.println(rs.getboolean(3));                 }             } catch (sqlexception ex) {                 ex.printstacktrace();             }          } 

you never bind value placeholder. placeholder should not contain % sign , single quotes.

it must like:

stm = connection.preparestatement("select * books name ? "); stm.setstring(1,"%"+your_string+"%") 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -