sql - java search-getting an integer value from a string preparedstatement -
i have java code, , want able search year (which int) textfield , show table. how implement in preparestatement? need parse?
try { connection = dbconnect.getconnection(); //int filmyear = integer.parseint(txtsearch.gettext()); statement = connection.preparestatement("select filmtitle, filmyear, filmgenre, companyname production, film, company (lower(filmtitle) lower (?) or " + "lower (filmgenre) lower (?) or filmyear = ?)and production.companyid = company.companyid , production.filmid = film.filmid"); statement.setstring(1, "%" +txtsearch.gettext()+"%"); statement.setstring(2, "%" +txtsearch.gettext()+"%"); // statement.setint(3, +txtsearch.gettext()); resultset = statement.executequery(); table.setmodel(dbutils.resultsettotablemodel(resultset)); }catch(sqlexception e) { e.printstacktrace(); } as can see tried create statement.setint(3, +txtsearch.gettext());, suspect wrong.
filmtitle, filmgenre, , filmyear in same table.
any appreciated thanks
i think tried this. should working fine.
int filmyear = integer.parseint(txtsearch.gettext()); then
statement.setint(3, filmyear);
Comments
Post a Comment