java - how to concat sql query using union operator -
string query="select * recommendation.sports feed like'%"+s1+"%' union "select * recommendation.software feed '%"+s1+"%' union "select * recommendation.website feed '%"+s1+"%' union "select * recommendation.others feed '%"+s1+"%' union "select * recommendation.business feed '%"+s1+"%'";
maybe mean this?
string query = "select * recommendation.sports feed '%" + s1 + "%' " + "union " + "select * recommendation.software feed '%" +s1+ "%' " + "union " + "select * recommendation.website feed '%" +s1+" %' " + "union " + "select * recommendation.others feed '%"+s1+"%' " + "union " + "select * recommendation.business feed '%" +s1+ "%'" ;
but advise utilize preparedstatements
on query avoid sql injection
.
string query = "select * recommendation.sports feed concat('%', ?, '%') " + "union " + "select * recommendation.software feed concat('%', ?, '%') " + "union " + "select * recommendation.website feed concat('%', ?, '%') " + "union " + "select * recommendation.others feed concat('%', ?, '%') " + "union " + "select * recommendation.business feed concat('%', ?, '%')" ; preparedstatement pstmt = con.preparestatement(query); pstmt.setstring(1, s1); pstmt.setstring(2, s1); pstmt.setstring(3, s1); pstmt.setstring(4, s1); pstmt.setstring(5, s1); resultset _result = pstmt.executequery();
java preparedstatement java mysql sql jdbc
No comments:
Post a Comment