oracle - Query returning only empty value in java -
i using java connect oracle.this code have used
public list<favouriteshop> getmyfavouriteshop(string username) { list<favouriteshop> res=null; res = this.getjdbctemplate().query("select * from(select tbl_orderdetails.branch_name myfavourite,tbl_orderdetails.branch_id branch_id tbl_orderdetails inner bring together tbl_ordermaster on tbl_orderdetails.order_master_id=tbl_ordermaster.ordermasterid tbl_ordermaster.user_id='"+username+"' grouping tbl_orderdetails.branch_name,tbl_orderdetails.branch_id order count(tbl_orderdetails.branch_name) desc) rownum<=3", new myfavourite()); homecoming res; } private class myfavourite implements rowmapper<favouriteshop> { public favouriteshop maprow(resultset rs,int i) throws sqlexception { favouriteshop g=new favouriteshop(); g.setbranch_id(rs.getstring("branch_id")); g.setmyfavourite(rs.getstring("myfavourite")); homecoming g; } } i tried execute same query in oracle getting output not here , getting empty result.
first, have possible sql injection. can avoid giving username argument query
this.getjdbctemplate().query("select * (... tbl_ordermaster.user_id=? ...) rownum<=3", new object[]{ username }, new myfavourite()); a possible reason empty result might
... tbl_ordermaster.user_id='"+username+"' ... usually, user_id integer value, compare string , enclose in quotes. passing username argument query shown above, should take care of this.
java oracle
No comments:
Post a Comment