• About

Luke's Tech Show

~ Knowledge is useless when not shared with others.

Luke's Tech Show

Monthly Archives: December 2013

Statement Handling Literal string with Single Quote (‘) in where clause criteria

10 Tuesday Dec 2013

Posted by Luke Tong in Java

≈ Leave a comment

In simple query using JDBC Statement, NOT PreparedStatement, you will get a SQL exception in statement like this one

select customer.* from t_customer_table customer
where customer.last_name = ‘O’Reilly’;

You can workaround this by replace the single quote inside the criteria value by two consecutive single quotes (”). Not this is no a double quote, but 2 single quotes.

select customer.* from t_customer_table customer
where customer.last_nam = ‘O”Reilly’;

Please keep in mind it is always highly recommenced to use prepared statement with parameters, then you would need this workaround. But in case you don’t don’t want to that, this solution comes in handy.

Advertisements
Advertisements

Subscribe

  • Entries (RSS)
  • Comments (RSS)

Archives

  • October 2018
  • September 2018
  • February 2018
  • January 2018
  • October 2017
  • July 2017
  • June 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • December 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013

Categories

  • Agile
  • Algorithm
  • Cloud
  • IT Misc
  • Java
    • Web Service
      • RESTful
  • Java8
  • JavaScript
    • jQuery
  • JBoss
  • JPA
  • Linux
  • MQ
  • Spring CORE
  • Spring MVC
  • TDD
  • Uncategorized

Meta

  • Register
  • Log in

Create a free website or blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy