SQL query inside java

-1

I have the following query inside a jsp file in Java.

String sql = "SELECT * FROM products WHERE productName = ? ";

I'd like my query to ignore camel case and return all words that were part of string . For example, Desktop would return desktop for camel case and phone strong> cellphone , etc.

How can I do this?

I've tried to use % , LIKE and it does not work.

    
asked by anonymous 08.09.2018 / 07:06

1 answer

2

For this, you must actually use the LIKE with the wildcard % .

If you are using a PreparedStatement , which is what it looks like, you will need to put the wildcard at the value you want to search, like this:

// vamos supor que existe uma variável 'productName' 
// onde teremos o valor a pesquisar
PreparedStatement pstmt = 
    con.prepareStatement("SELECT * FROM products WHERE productName LIKE ?");
pstmt.setString(1, "%" + productName + "%");

This will perform a search by the phone value at the beginning, middle, and end of all values in the productName column.

    
08.09.2018 / 12:15