Home arrow static arrow Java Programming [Archive] - Using wildcards in PreparedStatement
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Using wildcards in PreparedStatement
This topic has 1 reply on 1 page.

Posts:56
Registered: 2/16/03
Using wildcards in PreparedStatement  
Aug 2, 2004 4:29 PM



 

Hi,
i have had a look about the forum, and found a few answers but they seem to relate to MSSQL not MySQL.

I am using a PreparedStatement

  sql = "SELECT * FROM table WHERE postcode LIKE '%?%' ";            		  	     	     PreparedStatement psmt = connection.prepareStatement(sql);  		    	     	      psmt.setString(1, searchTerm );   		  	      rs = psmt.executeQuery(); 


However this throws an error, I have tried to find a way of escaping the % but no luck. The query runs fine when I use.

  sql = "SELECT * FROM table WHERE postcode LIKE ? ";


Thanks
George
 

Posts:27,518
Registered: 11/3/97
Re: Using wildcards in PreparedStatement  
Aug 2, 2004 5:21 PM (reply 1 of 1)



 
Like this (and it has nothing to do with the database vendor.)

sql = "SELECT * FROM table WHERE postcode LIKE ? ";
psmt.setString(1, "%" + searchTerm + "%" );
 
This topic has 1 reply on 1 page.