1
votes

I am using spring boot jdbctemplate to insert the records in the database. However I found using jdbctemplate.update(query) , where query is the string for inserting the records in the database.

I would like to insert the Apostrophe and special characters in the table columns but I get BadSqlGrammarException.

For example my query gets formed like this VALUES( 'abc's example ')

I saw Escaping a single quote when using JdbcTemplate , Where in comments it is written that using jdbctemplate.update(query,Object[] args) which creates the PreparedStatement , But I have Generic method which calls the jdbctemplate.update() method from every module of the code.

I would like to use this for both insert as well as update operations, as of now I am using jdbctemplate.update(query)

1

1 Answers

2
votes

In SQL single quotes are "escaped" by doubling them:

VALUES( 'abc''s example ')

But it would be much better to use a PreparedStatement instead.