• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question mark in PreparedStatement Parameter is preventing results.

 
Greg Bengis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi there

I have a Postgres DB, and in the one column of my page_request_log table, I have 'page', which would be a page name (and query string)

e.g.
|page|
/trunk/page/en/page1?ccs_clear_cache=1
/trunk/page/en/page1
/trunk/page/en/page1?something=else
/trunk/page/fr/page23

I am using a PreparedStatement to filter searches on this URL field.

String sql = "select * from page_request_log where page like ?"

I am adding my search filter to like so: stmt.setString(1, "%" + filter + "%");

Thing is, if I search for (where the value in quotes, is the value of variable "filter")
"/trunk/page", I get the 4 results (correct)
"/fr/", I get 1 result (correct)
"en/page1", I get 3 results (correct)
"ccs", I get 0 results (INCORRECT)
"page1?something", I get 0 results (INCORRECT)

so basically, anything which is part of the query string portion of the logged urls is NOT picked up by the search.

Since the ? is INSIDE my filter String variable, and not part of the PreparedStatement String, I can't figure out what it going on..

Any help would be appreciated!

Thanks

 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the relevant code, using code tags. I think I know how your code looks like from your description, but posting it will eliminate any guessing altogether.

Meanwhile, you might try to run the query in an SQL client, such as psql or TOAD, to verify that it returns what you expect. I don't use Postgres, but the documentation I looked up does not mention anything special about the question mark in the LIKE pattern.

And welcome to the Ranch!
 
Greg Bengis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martin

Thanks for your reply!

I am not sure if this happens often, but in shrinking down the code to send you a concise snippet, I discovered I'd done something else in the code (completely unrelated to the SQL portion) which was giving me unexpected results..

Sorry about that :/
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to be sorry about. This happens all the time. This is why I sometimes encourage people to create and post an SSCCE - more often than not the issue gets resolved in the process, and when it doesn't, it is easier for others to help.

A real code need not be involved: when I try to explain a problem to a colleague, very often I figure it out by myself in the process, just because when explaining it to someone I look at it from a new perspective.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i read about these when I was 16 in a trade mag, and it has always stuck
cardboard programmer
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy Gibbons wrote:i read about these when I was 16 in a trade mag, and it has always stuck
cardboard programmer


yes my childhood was that exciting i was reading computer mags in the loo.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic