Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2009
    Posts
    2

    Unanswered: encoding question marks in prepared statements

    I have a prepared sql statement and need to encode question marks that appear in strings..

    for example
    select * from topics where status=? and name="test?"

    i need to encode the question mark in the string test? otherwise db2 thinks this statement requires two parameters, vs one

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Have you tried using single-quotes, which are the standard SQL string delimiters?
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Jun 2009
    Posts
    2
    hi stolze...this was just an example I should have used single quotes instead of double..problem still remains...

    select * from topics where status=? and name='test?'

  4. #4
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    You could of course use
    Code:
    select * from topics where status=? and name=?
    and pass the text "test?" as a second parameter.
    Is that an option for you?
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting
    __http://www.abis.be/

  5. #5
    Join Date
    May 2003
    Posts
    113
    Quote Originally Posted by jamieal74
    I have a prepared sql statement and need to encode question marks that appear in strings..

    for example
    select * from topics where status=? and name="test?"

    i need to encode the question mark in the string test? otherwise db2 thinks this statement requires two parameters, vs one

    select * from topics where status=? and name like 'test'||?

  6. #6
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    I haven't tried this myself, but my first assumption would be that it simply works as you expect, i.e. the 2nd '?' nested inside the string is not considered to be a parameter marker. If my assumption is wrong, please provide the DB2 version you are using (on which platform) and the exact error message that you are getting.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •