Search code examples
mysqljspjsp-tags

Sql Query LIKE not working


Hi i have trying to do a query, that receives the value on a querystring, but is not working i think the query it self is no good. could you help me?

So i receive the query on

<%String detalhe = request.getParameter("value");%>

I wont put connections and stuff, because they work with other querys, so the problem are not the connections.

// sql query to retrieve values from the specified table. 

String QueryString = "SELECT * FROM ebooko.dadoslivros WHERE Autor LIKE '%"+detalhe+"%'

OR ano LIKE '%"+detalhe+"%'";;
rs = statement.executeQuery(QueryString);

It simply cannot retrive the value, i'm querying.

Adicional info: Table: dadoslivros Columns that i need to compare the value: Autor, ano.

for example when i run the Href the value that is passed is: Jules%Verne (i gess it changes SPACES with '%'.


Solution

  • Use URLDecoder#decode() to decode the parameters in the query string.

    You should also consider using a PreparedStatement to prevent SQL injection attacks.