org.springframework.jdbc.BadSqlGrammarException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Removed error-irrelevant translation stack frames from exception stack trace after exceptions were created by an SQLExceptionTranslator: When debugging Spring-JDBC queries, I find it distracting that the top stack frames always refer to SQLExceptionTranslator which is only called after an error occured that caused the exception. The translator only translates a "raw" exception into a richer exception. Therefore, I suggest that these stack entries are removed before the enriched exception is rethrown by the JdbcTemplate. It is a detail, but I believe the exception stack trace should not get polluted with details that merely reflect an implementation detail. This can also distract a user that tries debugging his/her application and who does not know how the exception handling is implemented in Spring. An example of how the stack trace looks like when using an invalid SQL statement within JdbcTemplate: {noformat} org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [This is not valid SQL]; nested exception is java.sql.SQLException: ORA-00900: invalid SQL statement at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714) at com.example.Main.main(Main.java:17) Caused by: java.sql.SQLException: ORA-00900: invalid SQL statement {noformat} With the patch the stack trace would look like: {noformat} org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [This is not valid SQL]; nested exception is java.sql.SQLException: ORA-00900: invalid SQL statement at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:614) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714) at com.example.Main.main(Main.java:17) Caused by: java.sql.SQLException: ORA-00900: invalid SQL statement {noformat} In this example, the exception is catched withing JdbcTemplate.execute, wrapped by an instance of SQLErrorCodeSQLExceptionTranslator and then rethrown. Since the SQLErrorCodeSQLExceptionTranslator is responsible for instantiating the wrapping exception, the exception's stack trace is pointing to the translator since Exception.fillInStackTrace is called in the exception's constructor (this is the default implementation of a Java exception.)
    via by Rafael Winterhalter,
  • Removed error-irrelevant translation stack frames from exception stack trace after exceptions were created by an SQLExceptionTranslator: When debugging Spring-JDBC queries, I find it distracting that the top stack frames always refer to SQLExceptionTranslator which is only called after an error occured that caused the exception. The translator only translates a "raw" exception into a richer exception. Therefore, I suggest that these stack entries are removed before the enriched exception is rethrown by the JdbcTemplate. It is a detail, but I believe the exception stack trace should not get polluted with details that merely reflect an implementation detail. This can also distract a user that tries debugging his/her application and who does not know how the exception handling is implemented in Spring. An example of how the stack trace looks like when using an invalid SQL statement within JdbcTemplate: {noformat} org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [This is not valid SQL]; nested exception is java.sql.SQLException: ORA-00900: invalid SQL statement at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714) at com.example.Main.main(Main.java:17) Caused by: java.sql.SQLException: ORA-00900: invalid SQL statement {noformat} With the patch the stack trace would look like: {noformat} org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [This is not valid SQL]; nested exception is java.sql.SQLException: ORA-00900: invalid SQL statement at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:614) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714) at com.example.Main.main(Main.java:17) Caused by: java.sql.SQLException: ORA-00900: invalid SQL statement {noformat} In this example, the exception is catched withing JdbcTemplate.execute, wrapped by an instance of SQLErrorCodeSQLExceptionTranslator and then rethrown. Since the SQLErrorCodeSQLExceptionTranslator is responsible for instantiating the wrapping exception, the exception's stack trace is pointing to the translator since Exception.fillInStackTrace is called in the exception's constructor (this is the default implementation of a Java exception.)
    via by Rafael Winterhalter,
  • GitHub comment 572#253589367
    via GitHub by patrickzurek
    ,
    • org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [This is not valid SQL]; nested exception is java.sql.SQLException: ORA-00900: invalid SQL statement at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:614) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714) at com.example.Main.main(Main.java:17)

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,