String Query="select * from recommendation.sports WHERE feed LIKE'%"+s1+"%'
UNION "select * from recommendation.software WHERE feed LIKE '%"+s1+"%'
UNION "select * from recommendation.website WHERE feed LIKE '%"+s1+"%'
UNION "select * from recommendation.others WHERE feed LIKE '%"+s1+"%'
UNION "select * from recommendation.business WHERE feed LIKE '%"+s1+"%'";
maybe you mean this?
String Query = "select * from recommendation.sports WHERE feed LIKE '%" + s1 + "%' " +
"UNION " +
"select * from recommendation.software WHERE feed LIKE '%" +s1+ "%' " +
"UNION " +
"select * from recommendation.website WHERE feed LIKE '%" +s1+" %' " +
"UNION " +
"select * from recommendation.others WHERE feed LIKE '%"+s1+"%' " +
"UNION " +
"select * from recommendation.business WHERE feed LIKE '%" +s1+ "%'" ;
but I advise you to use PreparedStatements on the query to avoid SQL Injection.
String Query = "select * from recommendation.sports WHERE feed LIKE CONCAT('%', ?, '%') " +
"UNION " +
"select * from recommendation.software WHERE feed LIKE CONCAT('%', ?, '%') " +
"UNION " +
"select * from recommendation.website WHERE feed LIKE CONCAT('%', ?, '%') " +
"UNION " +
"select * from recommendation.others WHERE feed LIKE CONCAT('%', ?, '%') " +
"UNION " +
"select * from recommendation.business WHERE feed LIKE 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();
Try This:
String Query="select * from recommendation.sports WHERE feed LIKE'%"+s1+"%'
UNION select * from recommendation.software WHERE feed LIKE '%"+s1+"%'
UNION select * from recommendation.website WHERE feed LIKE '%"+s1+"%'
UNION select * from recommendation.others WHERE feed LIKE '%"+s1+"%'
UNION select * from recommendation.business WHERE feed LIKE '%"+s1+"%'";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With