We are using Spring Batch in our application and after upgrading the SpringBoot Version from 2.7.X (uses spring batch 4.X) to 3.1.X (uses spring batch 5.x) version we are getting the exception while running the steps.
Error: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ (truncated)..."] Completed 500 INTERNAL_SERVER_ERROR
I created the batch tables manually in the DB and it still gives the same error.
Any suggestions?
I ran into a very similar issue when upgrading from Spring Boot 2.7 to 3.1, which also means moving from Spring Batch 4.x to 5.x.
The error you're seeing (PreparedStatementCallback; bad SQL grammar
) usually means that the batch metadata tables in your DB are not compatible with Spring Batch 5. This happens often when those tables were created manually based on the old schema (4.x).
Spring Batch 5 introduced some changes to the schema, so the old SQL table definitions won’t work anymore and lead to bad SQL grammar errors at runtime.
I solved it:
I dropped all the old batch tables I had manually created.
Then I used the official SQL script for Spring Batch 5 (e.g., schema-mysql.sql
, schema-postgresql.sql
, etc.) that comes with the Spring Batch 5 artifacts or repo.
I made sure the JobRepository
was being auto-configured correctly by Spring Boot (as long as the tables exist with the right schema, it usually works out of the box).
After doing that, my batch jobs worked without issues.