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