I have a Java application which queries a database table which the current user account may or may not have access to. If an exception is returned, I would like to distinguish between AccessDenied and the database server being down/offline. I expected that db2 would throw a PermissionDeniedDataAccessException when the user does not have select privileges on a table. However, when I tested it, db2 threw an InvalidDataAccessResourceUsageException.
Is it safe to catch an InvalidDataAccessResourceUsageException and handle it as an AccessDenied exception? Why doesn’t db2 throw a PermissionDeniedDataAccessException?
FYI: I am using the JDBC driver for db2 and not the ODBC driver so I expected better Java support.
If Spring exception translation algorithm incorrectly maps SQL exception code to the Spring’s exception, you can determine the SQL code yourself and customize exception translation, as described here: 12.2.4 SQLExceptionTranslator