Hello friends

String sql =  "SELECT * FROM work.cs_book WHERE bookname = ? AND author = ? AND category  = ?";

I have writtern above query and where i can search for a book based on bookname author and category. I am using preparedStatements to execute query.

However something is missing. How can i use wildcard search? like "Harry" search should also return "harry potter" book or "xxx harry yyy"

I tried

String sql =  "SELECT * FROM work.cs_book WHERE bookname LIKE ? AND author LIKE ? AND category LIKE ?";

however its not working at all....

I am not sure. It's gonna dealt with java/sql!!

Try using something like:

ps.setString(2, "%" + authorname + "%");

then do the same for the bookname parameter. Let me know if this helps, I am posting from mobile so cannot test.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.